Of course! "Doh!" on me...

FWIW, the reason I overlooked this might be a common one that others (doing a search) might also overlook, so I think it deserves a tad clarification --please correct me if I'm wrong on this:

"require" waits until runtime to bring the code in, unlike "use", which compiles the function into place before running. Hence, using "use" as I did causes the fatalsToBrowser() function to be called irrespective of the conditional in the if statement. The solution you showed, using the "require"/"import" combination, assures that the code doesn't get imported and used until runtime, allowing the conditional will be tested beforehand.

The reason this eluded me in the first place is because this is all taking place within a BEGIN block, which is executed at compile-time, not runtime. Here, it would have seemed irrelevant whether to use use or require, till I realized that all I'm doing is defining the function, set_message(). This function isn't getting called yet--it's just being defined. Later, if there are syntax errors that perl's compile phase will catch, then set_message() is called, which will then do the test, which then determines whether to imports fatalsToBrowser().

If my explanation is accurate, it could be useful for people who are looking to learn the subtle nuances between use and require.


In reply to Re^2: "Safe" ways for Carp to report errors to browser? by argv
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.