Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Advice on style

by chrestomanci (Priest)
on Nov 25, 2010 at 16:01 UTC ( #873670=note: print w/ replies, xml ) Need Help??


in reply to Advice on style

Firstly, do you need to export anything? If your module has an OO interface, then users will typically do:

use Your::Clever:Module; my $instance = Your::Clever:Module::new() $instance->some_function();

Secondly, if you read the POD for Exporter, then near the bottom they list a number of alternatives, many of them look much nicer. Exporter is an old module, and a lot of other stuff has come since, some of it will be better.

Having said that, I don't think it makes any difference. My gut feeling is that none of it matters until perl gets to the end of your source file (or package), and then considers everything at once. In other words it is just a style thing like tabs vs spaces for indent, and you should do what ever you or your local coding conventions prefer.

For myself, I am thinking that you have to use or require the exporter module, so it makes sense to put that use along with all the others, and then set-up the exports afterwards, Then again, I have just taken a look at some old perl I wrote about 8 years ago, and it is the other way around. I guess it makes no difference.


Comment on Re: Advice on style
Download Code
Re^2: Advice on style
by GrandFather (Cardinal) on Nov 26, 2010 at 00:01 UTC

    Actually users should never:

    my $instance = Your::Clever:Module::new();

    Instead they should:

    my $instance = Your::Clever:Module->new();

    which works better with inheritance and is more robust against changes to the OO hierarchy.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://873670]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-22 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls