I spent a good deal of time today trying to wrap my tiny brain around a very unintuitive problem in my perl code. The project I'm working on is around 3.2 k lines of code, 100 kbytes in size, so it took a fair amount of time to track my way through the various modules using other modules, etc. I finally narrowed it into a simple testcase script, which I present here:

#!/usr/bin/perl -w use strict; use warnings; BEGIN { $SIG{__WARN__} = sub { print $_[0]; }; $SIG{__DIE__} = sub { print $_[0]; exit(99); }; } use Storable; print "This script sucks\n";

Being a contrived example, the reasons for doing things aren't clear, but that's not important right now. As I am beginning to understand (although I'm not quite there yet), my usage of a $SIG{__WARN__}/$SIG{__DIE__} handler like that inside of a BEGIN block is bad practice. In the original code of course it wasn't in a begin block, but rather it was in the body of a module the main script included, and as such is evaluated at BEGIN time. Apparently, I shouldn't be doing things like defining a global warn or die handler from inside a module, and there's other ways to work around that.

But that's not the point. The point is, if you execute the quoted little scriptlet on my machine, you get the following output:

Can't locate Log/Agent.pm in @INC (@INC contains: /etc/perl /usr/lib/p +erl5/site_perl/5.8.5/i686-linux-thread-multi /usr/lib/perl5/site_perl +/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i686 +-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/v +endor_perl /usr/lib/perl5/5.8.5/i686-linux-thread-multi /usr/lib/perl +5/5.8.5 /usr/local/lib/site_perl .) at (eval 1) line 2.

Now, seeing as I've never heard of Log/Agent.pm, and I have no desire to have anyone logging anything for me, this little error was rather frightening. As it turns out, the Storable module included in the standard perl distribution optionally uses Log::Agent to help it give more informative warn/die messages, if Log::Agent happens to be installed (or at least, that's what I gather is going on).

Log::Agent is not in the standard distribution, and it's not normally an issue. I've used Storable all over the place in many projects, including this one, without the lack of Log::Agent ever becoming an issue. Only the above code snippet triggers this and seems to make Log::Agent a requirement. I have a feeling that Storable's use of Autoloader plays into this mess somewhere.

If you take the above script, and do any of the following three things to it, it suddenly doesn't have the "missing Log/Agent.pm" problem anymore:

Now whether my usage of the warn/die handlers was correct or not, this is just horrible buggy behavior in respones to it. However, I can't really track down the true nature of what's causing what to make this happen - I'd like to pin it down better and be able to submit a bug/patch to the Storable maintainers so that things work more cleanly and this issue either never happens, or at least gives a much more informative error that doesn't mention Log::Agent.

Thoughts? Anyone hit this mess before? ETA: Edited title later since apparently SIG{__DIE__} was the important part, not __WARN__


In reply to SIG{__DIE__}, Storable, and Log::Agent... by ph713

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.