Well, I don't quite follow your explanation (I'm not sure where set_message() appears - it's not in your sample code), so instead I'll just describe what happens.

When perl gets to the end of compiling a BEGIN block, it temporarily stops compiling, executes the code in the block, then continues compiling. Similarly, when Perl sees a 'use' while compiling, it temporarily stops the current compile, reads in the file referenced by the 'use', compiles it, executes it, calls the import function(), then continues off compiling at the statement following the 'use'.

In your original code, the Perl interpreter starts compiling the code in your BEGIN block, sees the 'use', reads in and compiles the file, calls its import method, then continues compiling the rest of the code in the BEGIN block. (At this point, the import has already affected the current package's symbol table for any subsequent code). Finally the end of the BEGIN block is reached, compilation pauses and the BEGIN block is executed.

At this point your if statement is executed, which by now has been optimised away to a noop, since it has an empty body (since 'use' is invisible at runtime).

Dave.


In reply to Re^3: "Safe" ways for Carp to report errors to browser? by dave_the_m
in thread "Safe" ways for Carp to report errors to browser? by argv

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.