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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.