Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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.

Replies are listed 'Best First'.
Re^2: Advice on style
by GrandFather (Sage) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://873670]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2018-04-22 03:37 GMT
Find Nodes?
    Voting Booth?