NAME
Reflex::Role::SigCatcher - add signal catching behavior to a class
VERSION
version 0.085
SYNOPSIS
package Reflex::Signal;
use Moose;
extends 'Reflex::Base';
has signal => (
is => 'ro',
isa => 'Str',
required => 1,
);
has active => (
is => 'ro',
isa => 'Bool',
default => 1,
);
with 'Reflex::Role::SigCatcher' => {
signal => 'signal',
active => 'active',
cb_signal => 'on_signal',
method_start => 'start',
method_stop => 'stop',
method_pause => 'pause',
method_resume => 'resume',
};
1;
DESCRIPTION
Reflex::Role::SigCatcher is a Moose parameterized role that adds signal-catching behavior to Reflex based classes. The SYNOPSIS is the entire implementation of Reflex::SigCatcher, a simple class that allows Reflex::Role::SigCatcher to be used as an object.
Reflex::Role::SigCatcher is not suitable for SIGCHLD use. The specialized Reflex::Role::PidCatcher class is used for that, and it will automatically wait() for processes and return their exit statuses.
Required Role Parameters
None. All role parameters as of this writing have what we hope are sensible defaults. Please let us know if they don't seem all that sensible.
Optional Role Parameters
signal
signal
sets the name of an attribute that will contain the signal name to catch. Signal names are as those found in %SIG.
TODO - However, it may also be convenient to specify the signal name in the role's parameters. General use cases don't usually require signals names to change. The indirection through signal
is currently useful for Reflex::Signal, however, so we probably need both modes. It might be better to provide two roles, one for each behavior, rather than one role that does both.
active
active
specifies whether Reflex::Role::SigCatcher should be created in the active, signal-watching state. All Reflex watchers are enabled by default. Set it to a false value, preferably 0, to initialize the catcher in an inactive or paused mode.
Signal watchers may be paused and resumed. See method_pause
and method_resume
for ways to override the default method names.
cb_signal
cb_signal
names the $self method that will be called whenever the signal named in <$self-
$signal()>> is caught. It defaults to "on_%s_caught", where %s is the name of the signal. So if the INT signal is being watched, cb_signal
will default to "on_INT_caught".
method_start
method_start
sets the name of the method that may be used to initially start catching signals. It's "start_%s" by default, where %s is the signal name being caught.
Reflex::Role::SigCatcher will automatically start watching for signals if the value of active
's attribute is true.
method_stop
method_stop
may be used to permanently stop signal catchers. Stopped catchers cannot be restarted, so use method_pause
if you need to temporarily disable signal watchers. method_resume
may be used to resume them again.
Signal catchers will automatically stop watching for signals upon DEMOLISH.
method_pause
method_pause
sets the name of the method that may be used to pause signal catching. It is "pause_%s" by default, where %s is the signal name being caught.
method_resume
method_resume
sets the name of the method that may be used to resume signal catching. It is "resume_%s" by default, where %s is the signal name being caught.
EXAMPLES
eg/eg-39-signals.pl shows how Reflex::Signal may be used with callbacks or promises.
Reflex::Signal is a simple class that watches for signals with Reflex::Role::SigCatcher.
SEE ALSO
Reflex Reflex::Signal Reflex::Role::PidCatcher Reflex::PID
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex