++ed by:
MRAMBERG PLICEASE KES YZHERNAND ILUX
1 non-PAUSE user
Author image Paul Evans

NAME

UV::Signal - Signal handles in libuv

SYNOPSIS

  #!/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();

DESCRIPTION

This module provides an interface to libuv's signal handle.

Signal handles will run the given callback on receipt of the specified signal.

EVENTS

UV::Signal inherits all events from UV::Handle and also makes the following extra events available.

signal

    $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.

METHODS

UV::Signal inherits all methods from UV::Handle and also makes the following extra methods available.

new

    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

    # 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.

Returns the $signal instance itself.

stop

    $signal->stop();

The stop method stops the handle. The callback will no longer be called.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.