SigAction-SetCallBack ================================== NAME SigAction::SetCallBack - set several callbacks for any signal Version 0.01 SYNOPSIS Example: #!/usr/bin/perl use strict; use warnings; use SigAction::SetCallBack; package Foo; sub my_hup_callback { my ($class) = @_; print "$class: HUP signal recieved in my_hup_callback!\n"; } SigAction::SetCallBack->sig_registry('HUP',\&my_hup_callback); sub my_anoter_hup_callback { my ($class) = @_; print "$class: HUP signal recieved in my_anoter_hup_callback!\n"; } SigAction::SetCallBack->sig_registry('HUP','my_anoter_hup_callback'); 1; # --------------- package Bar; sub some_int_action { my ($class) = @_; print "$class: INT (Ctrl+C) signal recieved in some_int_action!\n"; } SigAction::SetCallBack->sig_registry('INT',\&some_int_action); 1; # --------------- package main; kill HUP => $$; kill INT => $$; exit; # Output: # Foo: HUP signal recieved in my_hup_callback! # Foo: HUP signal recieved in my_anoter_hup_callback! # Bar: INT (Ctrl+C) signal recieved in some_int_action! DESCRIPTION Sometimes there is a need to define several callbacks in different packages. Generally, we override value the %SIG hash. And if definition different action for signal in (may be different) packages, will be called only the last callback. SigAction::SetCallBack allows you to create the call stack. The order of packets, which define the callbacks will not be respected. On the other hand, will be complied with the procedure for determining the callbacks within the package, and all callbacks will work. This package uses the POSIX. METHODS sig_registry($sig,$cb) Register a callback stack storadge. sig_registry preserves the procedures order for registering callbacks within each package. $sig - short name of the signal (ie, 'INT', 'HUP'). Do not use the full names of signals such as SIGINT, SIGHUP. Full list of signals, that supports your system, you can see by calling the command "kill -l" in shell. $cb - is the name of a class method for a callback or a reference to it. The first argumets, who will receive the callback is the name of the class. Returns true if successful. set_sa_mask($new_sa_mask) This method overrides the flag which can affect the behavior of the process in the processing of the signal. By default, this is 'SA_NODEFER'. * "SA_NOMASK" or "SA_NODEFER" - do not interfere with the signal at its processing. * "SA_NOCLDSTOP" - if signum is SIGCHLD, then a notice to stop the child process will not be received. * "SA_ONESHOT" or "SA_RESETHAND" - restore behavior of the signal after a one call handler. * "SA_ONSTACK" - call the signal handler stack additional signals provided by sigaltstack (2). If the additional stack is not available, then the stack will be used by default. * "SA_RESTART" - the behavior must conform to the semantics of BSD signals and allow some system calls work, while being processed signals. * "SA_SIGINFO" Returns true if successful. SEE ALSO * "POSIX" AUTHOR Ivan Sivirinov