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?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |