Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Suppose one is writing a module and needs to make use of $SIG{__WARN__} and $SIG{__DIE__}. What must one do to make ones warn and die handler play nicely with the warn and die handlers in other modules?

Replies are listed 'Best First'.
Re: Chaining/Stacking $SIG{__WARN__}
by Joost (Canon) on Mar 07, 2008 at 00:29 UTC
      I'd like to thank both of you for responding.
Re: Chaining/Stacking $SIG{__WARN__}
by hipowls (Curate) on Mar 07, 2008 at 00:40 UTC

    That depends on what you mean by play nicely. This will restore the previous signal handlers after leaving your function.

    sub do_something { local $SIG{__WARN__} = sub { ... }; # your stuff goes here ... } # previous version restored
    If you want to have your handler called and then the original then you will need to do a bit more work
    my $old_warn = $SIG{__WARN__}; $SIG{__WARN__} = sub { # your stuff $old_warn->(@_); }