This is a problem that originates from the difference between compile-time and run-time, and how the compile-time of one module is the run-time of modules it uses. Think about it: if module A uses module B, then module A's compile-time is not complete until after module B is both compiled *and* run. So... what if A uses B and B uses A? Then A's runtime wants to get tangled up in its *own* compile-time.

I'll skip the suspense and just tell you the specific answer to your problem, though: you have to wrap your @ISA = 'Exporter' and @EXPORT = ... bits of code in a BEGIN block. Look at the example below (to which I've added some verbose information, so that you can really see what's happening):

### XXA.pm ### package XXA; BEGIN { print ((" " x $main::x++) . "Beginning XXA compile\n") } use strict; #BEGIN { use Exporter; use vars qw( @ISA @EXPORT ); @ISA = qw( Exporter ); @EXPORT = qw( xxa ); } use XXB; BEGIN { print ((" " x $main::x) . "Just used XXB in XXA compile\n") } sub import { my ($self) = shift; print ((" " x $main::x) . "XXA->import called\n"); $self->export_to_level(1, @_); } sub xxa { xxb; } BEGIN { print ((" " x --$main::x) . " Finishing XXA compile\n") } 1; ### end XXA.pm ###
...
### XXB.pm ### package XXB; BEGIN { print ((" " x $main::x++) . "Beginning XXB compile\n") } use strict; #BEGIN { use Exporter; use vars qw( @ISA @EXPORT ); @ISA = qw( Exporter ); @EXPORT = qw( xxb ); } use XXA; BEGIN { print ((" " x $main::x) . "Just used XXA in XXB compile\n") } sub import { my ($self) = shift; print ((" " x $main::x) . "XXB->import called\n"); $self->export_to_level(1, @_); } sub xxb { xxa; } BEGIN { print ((" " x --$main::x) . " Finishing XXB compile\n") } 1; ### end XXB.pm ###
Now, just do this:
me@host> perl -c XXA.pm Beginning XXA compile Beginning XXB compile Beginning XXA compile Just used XXB in XXA compile Bareword "xxb" not allowed while "strict subs" in use at XXA.pm line 2 +6. BEGIN not safe after errors--compilation aborted at XXA.pm line 29. BEGIN failed--compilation aborted at XXB.pm line 15. BEGIN failed--compilation aborted at XXA.pm line 15. me@host:>

That's basically the situation you are in currently. Now, go and un-comment the BEGIN keyword before the Exporter blocks in those modules...

me@host> perl -c XXA.pm Beginning XXA compile Beginning XXB compile Beginning XXA compile Just used XXB in XXA compile Finishing XXA compile XXA->import called Just used XXA in XXB compile Finishing XXB compile XXB->import called Just used XXB in XXA compile Finishing XXA compile XXA.pm syntax OK me@host>

Voila! Problem fixed. This should really be in some sort of FAQ, somewhere... I've gotten into arguments with VERY experienced perl programmers about this very topic before (that you must *ALWAYS* but your @EXPORT and @ISA in begin blocks (or use base.pm for your @ISA declarations)).

------------ :Wq Not an editor command: Wq

In reply to Re: Serious Exporter Problems by etcshadow
in thread Serious Exporter Problems by PetaMem

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, details, 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, summary, 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.