in reply to Re^2: Library file or module for sharing code?
in thread Library file or module for sharing code?

The only important part that was missing was

@ISA= qw(Exporter);

But a better approach would be either:

*import= \&Exporter::import;

or, if you know you'll have a new enough version of Perl

use Exporter qw(import);

Because using inheritance to get a single method is a bad idea; it brings along too much unhelpful baggage.

- tye        

Replies are listed 'Best First'.
Re^4: Library file or module for sharing code? (import)
by bradcathey (Prior) on Dec 28, 2005 at 16:22 UTC

    Thanks tye, went with:

    *import= \&Exporter::import;

    which worked fine (though I have no idea what is going on there--nothing in the docs I could find :)


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      It just imports the import() sub "by hand" from Exporter.pm.

      use Common qw(Foo); becomes BEGIN { require "Common.pm"; Common->import("Foo") } and Common->import(...) can find the import() by inheritance (@ISA) or because Common::import itself has been defined. "Importing" just makes Common::import() another name for Exporter::import().

      - tye