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.


In reply to Re: Re: modules which includes eachs other by blssu
in thread modules which includes eachs other by chaos

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.