NAME
UV::Prepare - Prepare handles in libuv
SYNOPSIS
#!/usr/bin/env perl
use strict;
use warnings;
use UV;
# A new handle will be initialized against the default loop
my $prepare = UV::Prepare->new();
# Use a different loop
my $loop = UV::Loop->new(); # non-default loop
my $prepare = UV::Prepare->new(
loop => $loop,
on_close => sub {say "close!"},
on_prepare => sub {say "prepare!"},
);
# setup the handle's callback:
$prepare->on(prepare => sub {say "We're prepared!!!"});
# start the handle
$prepare->start();
# or, with an explicit callback defined
$prepare->start(sub {say "override any other callback we already have"});
# stop the handle
$prepare->stop();
DESCRIPTION
This module provides an interface to libuv's prepare handle.
Prepare handles will run the given callback once per loop iteration, right before polling for i/o.
EVENTS
UV::Prepare inherits all events from UV::Handle and also makes the following extra events available.
prepare
$prepare->on(prepare => sub { my $invocant = shift; say "We are here!"});
my $count = 0;
$prepare->on(prepare => sub {
my $invocant = shift; # the handle instance this event fired on
if (++$count > 2) {
say "We've been called twice. stopping!";
$invocant->stop();
}
});
When the event loop runs and the handle is ready, this event will be fired. UV::Prepare handles will run the given callback once per loop iteration, right before polling for i/o.
METHODS
UV::Prepare inherits all methods from UV::Handle and also makes the following extra methods available.
new
my $prepare = UV::Prepare->new();
# Or tell it what loop to initialize against
my $prepare = UV::Prepare->new(
loop => $loop,
on_close => sub {say "close!"},
on_prepare => sub {say "prepare!"},
);
This constructor method creates a new UV::Prepare 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
$prepare->start();
# pass a callback for the "idle" event
$prepare->start(sub {say "yay"});
# providing the callback above completely overrides any callback previously
# set in the ->on() method. It's equivalent to:
$prepare->on(idle => sub {say "yay"});
$prepare->start();
The start method starts the handle.
Returns the $prepare
instance itself.
stop
$prepare->stop();
The stop method stops the handle. The callback will no longer be called.
AUTHOR
Chase Whitener <capoeirab@cpan.org>
AUTHOR EMERITUS
Daisuke Murase <typester@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2012, Daisuke Murase.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.