rrwo has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on a module which traps warning and fatal signals in the BEGIN block:
$SIG{__WARN__} = \&foo;
$SIG{__DIE__} = \&bar;
All this works fine (well, I gotta work on trapping dies in `eval' but that's a separate issue). What doesn't work is when I use another module that also traps these, such as CGI::Carp.
If I `use' my module before CGI::Carp, my traps are lost. Likewise if I use mine after CGI::Carp, I kill its traps.
I've tried something like the following:
if ($SIG{__WARN__}) {
my $previous = $SIG{__WARN__};
$SIG{__WARN__} = sub {
# do my stuff
goto &$previous;
};
}
else
# blah blah
but this doesn't work! It repeatedly calls my handler over and over, as if $previous contained a reference to my code (I've debugged it and found $previous only contains something when a module such as CGI::Carp has trapped the signal).
So what am I doing wrong here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: How can two modules latch onto $SIN{__WARN__} or $SIG{__DIE__}?
by tilly (Archbishop) on Jan 10, 2001 at 07:59 UTC | |
by rrwo (Friar) on Jan 10, 2001 at 08:08 UTC | |
by tilly (Archbishop) on Jan 10, 2001 at 08:19 UTC | |
|
Re: How can two modules latch onto $SIN{__WARN__} or $SIG{__DIE__}?
by Adam (Vicar) on Jan 10, 2001 at 09:43 UTC |