in reply to Re: Weirdness with $SIG{__DIE__} (and __WARN__)
in thread Weirdness with $SIG{__DIE__} (and __WARN__)
Actually, I'm not sure I should have mentioned local. I think 5.6's our declaration is actually closer. But anyway, try this:
in A.pl
package A;
use Z;
$SIG{__DIE__} = sub { die 'in ' . __PACKAGE__ };
eval { die };
print "$@";
eval { Z::Zdie };
print "$@";
and in a separate file (Z.pm):
package Z;
$SIG{__DIE__} = sub { die 'in ' . __PACKAGE__ };
sub Zdie { die }
You'll get this output:
in A at A.pl line 5. in A at A.pl line 5.
A's signal handler is the one that is used for both deaths.
The reason I mentioned local is that some people try using local to 'fix' this (I know its not a bug) so that the each package could declare signal handlers.
Now change the top of A.pl to this:
package A;
use Sig::Lexical::Paranoid;
use Z;
$SIG{__DIE__} = sub { die 'in ' . __PACKAGE__ };
You'll get this:
in A at A.pl line 7. in Z at Z.pm line 3.
Note that despite the fact that A assigned directly to $SIG{__DIE__}, it did not overwrite Z's signal handler
This may be useful.
- dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Weirdness with $SIG{__DIE__} (and __WARN__)
by tye (Sage) on Jan 13, 2001 at 04:38 UTC | |
by autarch (Hermit) on Jan 13, 2001 at 13:58 UTC |