in reply to Re: how to import a module var
in thread how to import a module var

I want to second the above. It's always dodgy to export anything from an OO module. If your module has a method called new, you need a very good reason for it to export anything. If outsiders need to access it, make a method for them to use.

This is especially important when cross language programs come along. When Perl is tied to Java or Python, those other languages can't see the exports, they need methods to call.

Perhaps the only valid use of exports in the OO context is for mixin modules which provide exported subs that lots of other classes can import into their packages. But those exporting mixin providers don't have constructors. Which leaves me back at my rule of thumb: constructors and Exporter don't mix.

This is not to say that clever OO modules might not have a magical import that does all sorts of mischief (like fabricating whole classes). But they shouldn't actually put anything into the caller's name space like Exporter does.

Phil

Replies are listed 'Best First'.
Re^3: how to import a module var
by Perl Mouse (Chaplain) on Nov 22, 2005 at 14:36 UTC
    I sometimes export a constructor. Why? Because sometimes, I rather write:
    my $obj = new_feeble();
    than
    my $obj = Feeble->new();
    The former requires less tokens. ;-)

    And I'll export constants from my OO modules if I feel like it.

    Perl --((8:>*