UniEvent::Signal - runs callbacks upon UNIX signals
use UniEvent::Signal; # for constants my $h = UE::signal SIGINT, sub { say "got SIGINT" }; # more verbose way my $h = UniEvent::Signal->new(); $h->start(SIGINT, sub { my ($h, $signum) = @_; say "got signal $signum"; }); # one shot signal watcher $h->once(SIGTERM, sub { ... });
Allow to check UNIX signals and, if a signal appears, execute appropriate handlers during loop iteration.
It is inherited from UniEvent::Handle.
All methods of UniEvent::Handle also apply.
my $handle = UniEvent::Signal->create(SIGINT, sub { say "hi" });
Creates and starts a signal handle. Alias for new($loop) + start($signum, $callback).
new($loop)
start($signum, $callback)
my $handle = UniEvent::Signal->create_once(SIGINT, sub { say "hi" });
Creates and starts a one-shot signal handle. Alias for new($loop) + once($signum, $callback).
once($signum, $callback)
Constructs new Signal handle and binds it to the specified event loop.
Marks $signum to be permanently handled in the next event loop iterations.
$signum
If $callback is present, it is added as event()->add($cb)
$callback
May return error
Temporally marks $signum to be watched in the next event loop iteration(s). Upon $signum receiving, handle will no longer watch for it (as if stop() was called).
stop()
Stops the singal handle, i.e. makes it inactive for the next event loop iteration.
Callback signature:
my ($handle, $signum) = @_;
Where $handle is the Signal handle object itself.
$handle
$signum is the signal number that fired. It is useful when you add the same callback for several signal watchers.
See "EVENT CALLBACKS" in UniEvent
Method on_signal will be called.
on_signal
See "EVENT LISTENER" in UniEvent
Immediately ivokes assigned callbacks and listeners in the caller context (i.e. not waiting loop run) with the given signal.
Some signals might be not available for particular platforms.
To install UniEvent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UniEvent
CPAN shell
perl -MCPAN -e shell install UniEvent
For more information on module installation, please visit the detailed CPAN module installation guide.