Update:All problems have solutions and there's an explanation to my mystery below Re^2: Exporter (sometimes) doesn't seem to export if it's not first in @ISA:etadpU

I have a simple script:

#!/usr/bin/perl -w use Foo ; use Goo ; use Biz ; use Baz ; eval { &testfoo ; } ; warn $@ if $@ ; eval { &testgoo ; } ; warn $@ if $@ ; eval { &testbiz ; } ; warn $@ if $@ ; eval { &testbaz ; } ; warn $@ if $@ ;
with a few packages:
package Foo ; use base qw(Class::DBI) ; use vars qw(@ISA @EXPORT) ; require Exporter ; push @ISA, qw(Exporter) ; @EXPORT = qw/testfoo/ ; sub testfoo { print "It works\n" ; }
package Goo ; use base qw(Class::DBI) ; use vars qw(@ISA @EXPORT) ; require Exporter ; unshift @ISA, qw(Exporter) ; @EXPORT = qw/testgoo/ ; sub testgoo { print "It works\n" ; } 1 ;
package Biz ; use base qw(CGI) ; use vars qw(@ISA @EXPORT) ; require Exporter ; push @ISA, qw(Exporter) ; @EXPORT = qw/testbiz/ ; sub testbiz { print "It works\n" ; } 1 ;
package Baz ; use base qw(CGI) ; use vars qw(@ISA @EXPORT) ; require Exporter ; unshift @ISA, qw(Exporter) ; @EXPORT = qw/testbaz/ ; sub testbaz { print "It works\n" ; } 1 ;

Although they all look similar, my output is

$ perl test.pl It works It works Undefined subroutine &main::testbiz called at test.pl line 19. It works

Somehow, the location of "Exporter" within the ISA array makes a difference, and the difference is different if the other class in CGI or Class::DBI. It also seems to be different on different machines I use. My Mac produces the output above. I've got one Linux machine that gives the same result and another that gives the error whenever Exporter is listed second. I can't say what all the differences are between the machines; they're "pretty similar" but obviously something's different.

About the machines: They're more different than I thought, but not in any pattern I can see.

On Linux #1 (the "bad" one):

[mcdave@maia ~]$ uname -a Linux maia 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x +86_64 x86_64 GNU/Linux [mcdave@maia ~]$ perl -v This is perl, v5.8.8 built for x86_64-linux-thread-multi ... [mcdave@maia ~]$ perl -MExporter -e 'print $Exporter::VERSION, "\n"' 5.63 [mcdave@maia ~]$ perl -MCGI -e 'print $CGI::VERSION, "\n"' 3.15 [mcdave@maia ~]$ perl -MClass::DBI -e 'print $Class::DBI::VERSION, "\n +"' 3.0.17 [mcdave@maia ~]$ perl test.pl Undefined subroutine &main::testfoo called at test.pl line 9. It works Undefined subroutine &main::testbiz called at test.pl line 19. It works

On Linux #2 (the "good" one):

[mcdave@trowel ~]$ uname -a Linux trowel 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 + x86_64 x86_64 GNU/Linux [mcdave@trowel ~]$ perl -v This is perl, v5.8.8 built for x86_64-linux-thread-multi ... [mcdave@trowel ~]$ perl -MExporter -e 'print $Exporter::VERSION, "\n"' 5.58 [mcdave@trowel ~]$ perl -MCGI -e 'print $CGI::VERSION, "\n"' 3.15 [mcdave@trowel ~]$ perl -MClass::DBI -e 'print $Class::DBI::VERSION, " +\n"' 3.0.17 [mcdave@trowel ~]$ perl test.pl It works It works Undefined subroutine &main::testbiz called at test.pl line 19. It works

Update: the real difference appears to be neither in Exporter nor Class::DBI nor CGI. The CGI piece was an interesting red herring in my original problem, and I've learned something about Exporter now. But the real, interesting difference was down in one of the superclasses of Class::DBI. Namely, Class::Accessor was version 0.34 on the "bad" machine and version 0.33 on the "good" machine.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.