When setting a signal handler in a module, the problem arises that the application using the module already might have a signal handler set up for the signal in question.
So, for example, if a module FooFramework sets
$SIG{HUP} = sub { print "Framework handler!\n"; };
but the application FooApp has already set
$SIG{HUP} = sub { print "FooApp handler!\n"; };
then loading module FooFramework would actually disrupt the application by nuking its signal handler.
So, if FooFramework wants to play nice, it should check if there's already a SIG handler defined and, if so, stack its handler on top of it by wrapping around FooApp's handler:
my $old_handler = $SIG{HUP};
$SIG{HUP} = sub {
print "Framework handler!\n";
$old_handler->(@_) if defined $old_handler;
}
which works as long as FooApp doesn't set $SIG{HUP} to 'DEFAULT' or 'IGNORE'.
Now, this could be checked as well, but it feels like re-inventing the wheel. I'm wondering if there's a standard mechanism for handling these cases? Like, a %SIG slot with a ref to an array of handlers? Any help appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.