in reply to Re: modules which includes eachs other
in thread modules which includes eachs other
When package B executes use A, the A::import sub will not be compiled yet. That might cause trouble if side-effects from the import are expected.
I'd probably use require A to make it explicit that I'm not expecting A::import to run.
Update: Here's a little bit of code that lets you see how modules are loaded and imported. Each file needs to be saved separately -- if you combine packages into the same file, it won't work the same.
red.vulpes.com:~% more t.pl BEGIN { unshift @INC, sub { my($self, $file) = @_; print "loading $file\n"; return } } use Foo qw(t.pl); print "in t.pl\n"; red.vulpes.com:~% more Foo.pm package Foo; use Bar qw(Foo.pm); sub import { local $" = ', '; print "Foo::import(@_)\n"; } 1; red.vulpes.com:~% more Bar.pm package Bar; use Foo qw(Bar.pm); sub import { local $" = ', '; print "Bar::import(@_)\n"; } 1; red.vulpes.com:~% perl -w t.pl loading Foo.pm loading Bar.pm Bar::import(Bar, Foo.pm) Foo::import(Foo, t.pl) in t.pl
In the last bit of output above, notice the expected line "Foo::import(Foo, Bar.pm)" is missing. That's because Foo::import hasn't been compiled when Bar tries to execute it.
|
---|
Replies are listed 'Best First'. | |
---|---|
(bbfu) (moving use) Re3: modules which includes eachs other
by bbfu (Curate) on Oct 02, 2002 at 21:15 UTC |