For those of you who are confused by all this (and who wouldn't be): A used module's "runtime" is still the main program's "compile time". At the time that the main program invokes import, the module's top level code will already have been run.

Try this for a demo. Save it into 3 files, as indicated:

# Module Foo2, file Foo2.pm package Foo2; warn "module Foo2's run time"; BEGIN { warn "module Foo2's compile time"; } use Foo1; BEGIN { warn "module Foo2's compile time"; } sub import { warn "$_[0]\->import() called from " . caller; } warn "module Foo2's run time"; 1; # Module Foo1, file Foo1.pm package Foo1; warn "module Foo1's run time"; BEGIN { warn "module Foo1's compile time"; } sub import { warn "$_[0]\->import() called from " . caller; } warn "module Foo1's run time"; 1; # main script warn "Main script, runtime"; BEGIN { warn "Main script compile time"; } use Foo2; warn "Main script, runtime"; BEGIN { warn "Main script compile time"; }
Result:
Main script compile time at test.pl line 4.
module Foo2's compile time at Foo2.pm line 4.
module Foo1's compile time at Foo1.pm line 4.
module Foo1's run time at Foo1.pm line 3.
module Foo1's run time at Foo1.pm line 8.
Foo1->import() called from Foo2 at Foo1.pm line 6.
module Foo2's compile time at Foo2.pm line 6.
module Foo2's run time at Foo2.pm line 3.
module Foo2's run time at Foo2.pm line 10.
Foo2->import() called from main at Foo2.pm line 8.
Main script compile time at test.pl line 7.
Main script, runtime at test.pl line 3.
Main script, runtime at test.pl line 6.

As you can see, the "compile time" and "run time" messages are clearly intertwined. But one thing is for sure: import is called after the runtime for a module is completed, after the second warning for "runtime", at the end of the script, lines 8 and 10 respectively.

Conclusing: use Exporter(); or require Exporter;, it doesn't actually matter.


In reply to Re(3+): Module Inheritance by bart
in thread Module Inheritance by ronniec

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.