in reply to "use base" or @ISA

As an aside, I hate inhererting from Exporter. My class does NOT have an ISA relationship with Exporter! (And inheriting an autoload? ouch!) Below is an alternative.

Instead of:

use vars qw( @ISA @EXPORT_OK %EXPORT_TAGS ); BEGIN { @ISA = qw( Exporter ); @EXPORT_OK = qw( ... ); %EXPORT_TAGS = ( ... ); # if necessary use Exporter; }

try:

use vars qw( @EXPORT_OK %EXPORT_TAGS ); BEGIN { @EXPORT_OK = qw( ... ); %EXPORT_TAGS = ( ... ); # if necessary require Exporter; *import = \&Exporter::import; }

Update: s/module/class/;

Replies are listed 'Best First'.
Re^2: "use base" or @ISA
by kscaldef (Pilgrim) on Aug 17, 2004 at 17:20 UTC

    My module does NOT have an ISA relationship with Exporter!

    Really? So, how would you explain the relationship? Your module exports; it is an exporter.

      My module does NOT have an ISA relationship with Exporter!

      Really? So, how would you explain the relationship? Your module exports; it is an exporter.

      I would say that the module "delegates to Exporter", or "uses Exporter".

      Delegation and composition are perfectly valid implementation mechanisms, and there's no reason to view inheritance as the one true way of sharing functionality.

        In Perl 6 terms, it "does" Exporter rather than "is" Exporter. That is, Exporter is a role rather than a class. (It's a form of composition, really.) The Exporter role in Perl 6 would presumably supply importation as a submethod rather than a method, so that it's not inherited by subclasses.

        It could also be done with delegation, but in that case it "has" an Exporter object.

        Of course, Perl 6 might not use an Exporter class or role at all, since the standard export mechanism will be built in, and (we hope) fast.

      oops, that was a typo or a freudian slip or something. I meant to say my class isn't an exporter. A dog (for example) is an animal, but a dog isn't an exporter (although the package in which dog is defined might be). That's just my way of looking at things, so use the style you like the most.
Re^2: "use base" or @ISA
by Aristotle (Chancellor) on Aug 18, 2004 at 11:34 UTC

    I use Exporter::Lite. It is much lighter and has a clean interface (its import() is simply exported). It doesn't support tags, but then I never needed them anyway.

    Exporter::Tidy is another alternative if you need advanced features (some of which Exporter doesn't even offer.)

    Makeshifts last the longest.

Re^2: "use base" or @ISA
by Prior Nacre V (Hermit) on Aug 19, 2004 at 10:58 UTC

    Exporter has:

    package YourModule; use Exporter qw( import );

    under the heading Exporting without inheriting from Exporter.

    Regards,

    PN5