http://qs1969.pair.com?node_id=736424


in reply to Re^3: regarding 1.02 (was Re: IO::Lambda: call for participation)
in thread IO::Lambda: call for participation

So these are really "on_next_writable" and "on_next_readable" rather than general event handlers. (Unless they are reset with again().) That's definitely different from POE, in which event handlers persist once set.

So, conceptually, it's sort of like this (in a sort of pseudo-code and with some lexical scope differences so that the function references are explicit which I think makes the order of execution clearer):

my ($req, $socket, $buf); sub talk { $req = shift; $socket = IO::Socket::INET-> new( PeerAddr => 'www.perl.com', PeerPo +rt => 80); return lambda \&init; } sub init { when_writeable( $socket, \&write_handler ); } sub write_handler { send_request( $req => $socket ); when_readable( $socket, \&read_handler ); } sub read_handler { read_stuff( $socket => $buf ) or die; if ( done() ) { return $buf; } else { when_readable( $socket, \&read_handler ); } } my $q = talk( HTTP::Request-> new( GET => 'http://www.perl.com') ); print $q->wait;

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.