NAME
IO::Async::SignalProxy
- a class to allow handling of POSIX signals with IO::Async
-based IO
SYNOPSIS
Usually this object would be used indirectly, via an IO::Async::Set
:
use IO::Async::Set::...;
my $set = IO::Async::Set::...
$set->attach_signal( HUP => sub { reread_config() } );
It can also be used directly:
use IO::Async::SignalProxy;
my $sigproxy = IO::Async::SignalProxy->new(
signal_HUP => sub { reread_config() },
);
$sigproxy->attach( TERM => sub { print STDERR "I should exit now\n" } );
my $set = IO::Async::Set::...
$set->add( $sigproxy );
DESCRIPTION
This module provides a class that allows POSIX signals to be handled safely alongside other IO operations on filehandles in an IO::Async::Set
. Because signals could arrive at any time, care must be taken that they do not interrupt the normal flow of the program, and are handled at the same time as other events in the IO::Async::Set
's results.
CONSTRUCTOR
$proxy = IO::Async::SignalProxy->new( %params )
This function returns a new instance of a IO::Async::SignalProxy
object. The %params
hash takes keys that specify callback functions to run when signals arrive. They are all of the form
signal_$NAME => sub { ... }
where $NAME
is the basic POSIX name for the signal, such as TERM
or CHLD
.
METHODS
$proxy->attach( $signal, $code )
This method adds a new signal handler to the proxy object, and associates the given code reference with it.
- $signal
-
The name of the signal to attach to. This should be a bare name like
TERM
. - $code
-
A CODE reference to the handling function.
$proxy->detach( $signal )
This method removes a signal handler from the proxy object. Any signal that has previously been attach()
ed or was passed into the constructor may be detached.
SEE ALSO
POSIX for the
SIGname
constants
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>