Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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]
[chacham]: i'm reading an article on and thee is a disturbing message on the bottom right that says, "Fork me on GitHub". Maybe i just have a dirty mind.
[choroba]: Check the ninja on
[chacham]: oh my...
[Corion]: choroba++ # fixed width
marto has a Dirty_Mind on vinyl
[Corion]: Heh. The upside of this phone call was at least commendations from my cow-orkers on how clam I stayed and how I always brought the topic back to my priorities and the established processes of $work (them only getting half of the conversation).

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-08-17 13:02 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (287 votes). Check out past polls.