Howdy!

I'm going to number the lines so it's easier to follow the flow...

1 package a; 2 BEGIN { 3 use Data::Dumper; 4 print STDERR 'a:',Dumper \%INC; 5 } 6 use b; 7 my $a = { foo => &b::bar () }; 8 1; 9 10 b.pm: 11 12 package b; 13 14 BEGIN { 15 use Data::Dumper; 16 print STDERR 'b:',Dumper \%INC; 17 } 18 use c; 19 sub bar { 1; } 20 1; 21 22 c.pm: 23 24 package c; 25 BEGIN { 26 use Data::Dumper; 27 print STDERR 'c:',Dumper \%INC; 28 } 29 use a; 30 1;
Now, you say perl -c a.pm...that begins at line 1.

Lines 2 through 5 get compiled and immediately executed. Line 6 gets compiled, and leads to b.pm being processed. Move to line 12.

Lines 14-17 get compiled and executed. Line 18 gets compiled and leads to c.pm being processed. Move to line 24.

Lines 24-28 get compiled and executed. Line 29 now causes a.pm to get processed (again). Since a.pm has not yet been required or used, it gets run through the mill a second time. Move to line 1.

Lines 1-8 get compiled, then executed. Since b has already been used, it should get skipped (but import gets run, in the general case). Next, it turns to line 7 and executes it. That attempts to execute b::bar, but we have not yet gotten to line 19 in b.pm to define that subroutine.

Here the execution blows up.

Now, the problem is that you are use-ing modules that do more than define subroutines. When naked code calls routines in other modules, those routines had best be defined before you execute them. Better is to simply avoid getting into those situations.

Consider switching lines 18 and 19 and see what happens...

yours,
Michael

In reply to Re: Circular module dependencies by herveus
in thread Circular module dependencies by jmo

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.