|
EV::Bind - Easier Interface To EV's Callbacks |
EV::Bind - Easier Interface To EV's Callbacks
use EV; use EV::Watcher::Bind;
EV::io_bind($fh, $mask, $callback, @args);
Highly experimental. You've been warned.
EV::Watcher::Bind provides a simple interface to EV.pm's watcher methods that allows you to bind arguments as well as the watcher being created to the callback being registerd.
If you have, for example, an object that you want to use as your callback, you always need to do
my $obj = ...;
my @args = (1, 2, 3);
my $io = EV::io($fh, $mask, sub { $obj->foo(@args) });
With EV::Watcher::Bind, you can do
my $io = EV::io_bind($fh, $mask, \&foo, $obj, @args);
The functions provided by EV::Watcher::Bind also has the advantage of
passing you the EV::Watcher object that caused your callback to execute
as the last argument in your callback. In the above example, foo() could
have be implemented like so:
sub foo {
my ($self, $arg1, $arg2, $arg3, $w) = @_;
$w->stop;
}
EV::Watcher::Bind provides the following functions:
Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
|
EV::Bind - Easier Interface To EV's Callbacks |