Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Re: modules which includes eachs other

by blssu (Pilgrim)
on Oct 02, 2002 at 18:11 UTC ( #202341=note: print w/replies, xml ) Need Help??

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. more BEGIN { unshift @INC, sub { my($self, $file) = @_; print "loading $file\n"; return } } use Foo qw(; print "in\n"; more package Foo; use Bar qw(; sub import { local $" = ', '; print "Foo::import(@_)\n"; } 1; more package Bar; use Foo qw(; sub import { local $" = ', '; print "Bar::import(@_)\n"; } 1; perl -w loading loading Bar::import(Bar, Foo::import(Foo, in

In the last bit of output above, notice the expected line "Foo::import(Foo," 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

    Well, in this simple case, you could just move the use Bar qw(; in to after the sub import { ... } declaration.

    Of course, that might not work for some, more complicated situations. *shrug*

    Black flowers blossum
    Fearless on my breath

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://202341]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-10-26 09:45 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.