ph713 has asked for the wisdom of the Perl Monks concerning the following question:
#!/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__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SIG{__WARN__}, Storable, and Log::Agent...
by bmann (Priest) on May 06, 2005 at 20:49 UTC | |
by ph713 (Pilgrim) on May 06, 2005 at 21:00 UTC | |
by ph713 (Pilgrim) on May 06, 2005 at 21:23 UTC | |
|
Re: SIG{__DIE__}, Storable, and Log::Agent...
by Anonymous Monk on May 07, 2005 at 13:44 UTC |