in reply to Exporter (sometimes) doesn't seem to export if it's not first in @ISA

use Module; -and- use Module qw( ... );
are basically the same as
BEGIN { require Module; Module->import(); } -and- BEGIN { require Module; Module->import(qw( ... )); }

Your module doesn't have an import method, so the modules in @ISA are searched for one. Both CGI and Exporter have an import function, so the one that will be called will be controlled by the order of the classes in @ISA.

If you want Exporter's import, put Exporter early enough in @ISA or add the following to your module:

{ no warnings 'once'; *import = \&Exporter::import; }

(For what it's worth, I've always thought Exporter's reliance on inheritance is dumb.)

Replies are listed 'Best First'.
Re^2: Exporter (sometimes) doesn't seem to export if it's not first in @ISA
by mcdave (Beadle) on Apr 15, 2010 at 17:28 UTC

    That's interesting and very clear. And it led me straight to the solution for my particular case about Class::DBI on the different machines. Both have version 3.0.17 of Class::DBI, but on Linux #1:

    [mcdave@maia ~perl -MClass::DBI -MClass::ISA -e 'foreach $f (Class::IS +A::super_path("Class::DBI")) { print join(" ", $f, ${"${f}::VERSION"} +, "\n" ) ;}' Class::DBI::__::Base -1, set by base.pm Class::Accessor 0.34 Class::Data::Inheritable 0.08 Ima::DBI 0.35 [mcdave@maia ~]$ perl -MClass::DBI -e 'print Class::DBI->can("import") + ? "yes" : "no", "\n"' yes
    but on Linux #2:
    [mcdave@trowel ~]$ perl -MClass::DBI -MClass::ISA -e 'foreach $f (Clas +s::ISA::super_path("Class::DBI")) { print join(" ", $f, ${"${f}::VERS +ION"}, "\n" ) ;}' Class::DBI::__::Base -1, set by base.pm Class::Accessor 0.33 Class::Data::Inheritable 0.08 Ima::DBI 0.35 [mcdave@trowel ~]$ perl -MClass::DBI -e 'if( Class::DBI->can("import" +) ) { print "yes" } else { print "no" }; print "\n"' no
    So I conclude that the "difference" is in Class::Accessor!

    Thanks for your clear explanation