UV::Signal - Signal handles in libuv
#!/usr/bin/env perl use strict; use warnings; use UV; use UV::Signal qw(SIGINT); # A new handle will be initialised against the default loop my $signal = UV::Signal->new(signal => SIGINT); # Use a different loop my $loop = UV::Loop->new(); # non-default loop my $signal = UV::Signal->new( loop => $loop, on_close => sub {say "close!"}, on_signal => sub {say "signal!"}, ); # setup the signal callback: $signal->on(signal => sub {say "We get SIGNAL!!!"}); # start the check $signal->start(); # or, with an explicit callback defined $signal->start(sub {say "override any 'signal' callback we already have"}); # stop the signal $signal->stop();
This module provides an interface to libuv's signal handle.
Signal handles will run the given callback on receipt of the specified signal.
UV::Signal inherits all events from UV::Handle and also makes the following extra events available.
$signal->on("signal", sub { my ($invocant, $signum) = @_; say "We get signal"; });
When the event loop runs and the signal is received, this event will be fired.
UV::Signal inherits all methods from UV::Handle and also makes the following extra methods available.
my $signal = UV::Signal->new(signal => SIGFOO); # Or tell it what loop to initialize against my $signal = UV::Signal->new( loop=> $loop, on_close => sub {say 'close!'}, on_signal => sub {say 'signal!'}, );
This constructor method creates a new UV::Signal object and initializes the handle with the given UV::Loop. If no UV::Loop is provided then the "default_loop" in UV::Loop is assumed.
# start the handle with the callback we supplied with ->on() or with no cb $signal->start(); # pass a callback for the "signal" event $signal->start(sub {say "yay"}); # providing the callback above completely overrides any callback previously # set in the ->on() method. It's equivalent to: $signal->on(signal => sub {say "yay"}); $signal->start();
The start method starts the handle.
Note that the signal number is given to the constructor, not the start method.
start
Returns the $signal instance itself.
$signal
$signal->stop();
The stop method stops the handle. The callback will no longer be called.
Paul Evans <leonerd@leonerd.org.uk>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install UV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UV
CPAN shell
perl -MCPAN -e shell install UV
For more information on module installation, please visit the detailed CPAN module installation guide.