in reply to SIG{__DIE__}, Storable, and Log::Agent...

perldoc perlvar has this to say:

Due to an implementation glitch, the $SIG{__DIE__} hook is called even inside an eval(). Do not use this to rewrite a pending exception in $@, or as a bizarre substitute for overriding CORE::GLOBAL::die(). This strange action at a distance may be fixed in a future release so that $SIG{__DIE__} is only called if your program is about to exit, as was the original intent. Any other use is deprecated.

The key line is "even inside an eval()". Log::Agent is not found in the eval, and perl calls your DIE hook.

Not knowing more about what you are trying to accomplish, I can only suggest moving the begin block after the use Storable; line.

Replies are listed 'Best First'.
Re^2: SIG{__WARN__}, Storable, and Log::Agent...
by ph713 (Pilgrim) on May 06, 2005 at 21:00 UTC
    That explains a lot. "Strange action at a distance" is a lot more polite than what I would call it though. Storable is a pretty important core module, and the resulting error message makes absolutely no sense to the user.

    When perlvar says "Do not use this to ..., or as a bizarre substitute for overriding CORE::GLOBAL::die()", what exactly do they mean? I though that the entire purpose of $SIG{__DIE__} was exactly for overriding the global die() functionality.

    Perhaps my question should permute into this:

    I have a ton of code, much of it in modules, which in turn use other modules I've written, which in turn also use some 3rd party and/or core modules. When I execute the top level scripts that drag all of this in, I would like to enforce that all die()s and warn()s that happen, regardless of the module they occur in, call my special die/warn handlers to handle all of the error output in a consistent fashion.

    Since there are many top-level scripts, I would prefer to wrap the die/warn-handling code into another module, say named "MyProject::ErrorHandler", which I include in the top level scripts and/or the various modules I have control over. How does one go about accomplishing this correctly, without screwing up die()'s that occur in evals, which some modules (even my own) depend on.

      #!/usr/bin/perl -w use strict; use warnings; BEGIN { $SIG{__DIE__} = sub { die @_ if !defined($^S); die @_ if $^S; print "SIG{__DIE__} handling the following error: " . $_[0]; exit(99); }; } use Storable; print "This script sucks\n"; die "I will now die because I suck";
      ^^^ This seems to do what I want to do. perldoc -f die seems to think I should only need the "die @_ if $^S", but I've found the line before it with "die @_ if !defined($^S)" is also neccesary, at least in this example. According to perldoc perlvar:
       $^S     Current state of the interpreter.
      
                         $^S         State
                         ---------   -------------------
                         undef       Parsing module/eval
                         true (1)    Executing an eval
                         false (0)   Otherwise
      
                     The first state may happen in $SIG{__DIE__} and $SIG{__WARN__} handlers.
      
      In my case, it seems only the "0" case is what I want to be handling directly.