There are currently a wide range of AnyEvent utility modules in the work. Searching for AnyEvent on CPAN will show that there is AnyEvent::AIO for real asynchronous IO integrated
with event loops. Also AnyEvent::BDB, AnyEvent::HTTPD and Net::IRC3 and Net::XMPP2 also have AnyEvent support. AnyEvent::Handle provides a more highlevel way of handling filehandles with AnyEvent, see this example:
use AnyEvent::Handle;
my $cv = AnyEvent->condvar;
my $ae_fh =
AnyEvent::Handle->new (
fh => \*STDIN,
on_eof => sub { $cv->broadcast }
);
$ae_fh->push_read_line (sub {
my ($ae_fh, $line) = @_;
print "Got line [$line]\n";
$ae_fh->push_read (sub {
my ($ae_fh) = @_;
print "Got additional data:[\n".$ae_fh->rbuf."]\n";
if ($ae_fh->rbuf =~ s/^.*\bend\b//s) {
print "'end' detected, stopping program\n";
$cv->broadcast;
return 1;
}
return 0;
});
});
$cv->wait;
(Note: See also the examples in the distribution of AnyEvent and it's POD docs.)
There are also utility functions for non-blocking socket creation planned for next releases of AnyEvent. And one
day there will hopefully also a HTTP client module with AnyEvent support, perhaps someone would like to write it?
|