http://www.perlmonks.org?node_id=873670


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 (Saint) 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