in reply to AnyEvent for I/O events

i like the idea behind AnyEvent, but would like to see more building blocks for performing common tasks, like POE has. i'm particularly interest in writing a web client and am not looking forward to creating the equivalent of POE::Component::Client::HTTP.

Replies are listed 'Best First'.
Re^2: AnyEvent for I/O events
by Corion (Patriarch) on May 11, 2008 at 07:46 UTC

    See Coro::LWP. The basic idea of Coro is to subvert non-Coro modules by making their sockets coro-enabled. I haven't tried it under Windows, but as 4.7 now has support for ActiveState and Strawberry Perl, it might even work there.

Re^2: AnyEvent for I/O events
by elmex (Friar) on May 15, 2008 at 07:49 UTC
    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?

Re^2: AnyEvent for I/O events
by Anonymous Monk on Jun 06, 2008 at 07:33 UTC
    The AnyEvent module family grows steadily - AnyEvent::HTTP seems to have hit CPAN just now, and while it isn't as advanced as LWP, it might do what you need. Besides, AnyEvent isn't exclusive as other such "frameworks" - you can mix POE components easily with anyevent modules and code.

      There is a whole set of modules now in the AnyEvent suite:

      • AnyEvent::DNS - fully asynchronous DNS resolution
      • AnyEvent::BDB - truly asynchronous berkeley db access
      • AnyEvent::AIO - truly asynchronous file and directrory I/O
      • AnyEvent::DBI - asynchronous DBI access
      • AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client
      • AnyEvent::FastPing - quickly ping a large number of hosts

      Modules that also implement protocols are:

      • Net::IRC3 - An event system independend IRC protocol module
      • Net::XMPP2 - An implementation of the XMPP Protocol

      The great thing is, that you can combine all these protocols and modules in one application or module without threading and without having to choose a specific event loop implementation.

      I wrote Net::IRC3 and Net::XMPP2, and was really happy I could shift the choice of the event loop to the actual application programmer, who uses my module, making it a lot more useful (This way even the POE or IO::Async world can benefit from my modules).