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 ###
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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |