POE, Reflex, AnyEvent, Coro.pdf - The Lack Thereof
POE, Reflex, AnyEvent, Coro.pdf - The Lack Thereof
POE, Reflex, AnyEvent, Coro.pdf - The Lack Thereof
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>POE</strong>, <strong>Reflex</strong>, <strong>Coro</strong>, <strong>AnyEvent</strong>, ...Brock Wilcoxawwaiid@thelackthereof.orgYAPC::NA 2011
Hello
<strong>POE</strong>
<strong>Reflex</strong>
<strong>Coro</strong>
<strong>AnyEvent</strong>
<strong>Coro</strong><strong>AnyEvent</strong><strong>Reflex</strong><strong>POE</strong>
<strong>Coro</strong><strong>AnyEvent</strong><strong>Reflex</strong><strong>POE</strong>
Buyer Beware
Commonalities
use X;
(except <strong>Reflex</strong>)
Concurrency
TIMTOWTDI
Concurrency
wrong
(side note:“wrong” looks wrongwhen you look at it toolong)
wrong
well, a littlewrong
“it”
your code
what problemyour codesolves
whatyour codedoes
how you writeyour code
“Step back! ...”
Concurrency
IRC Client
connect / disconnect serversjoin / part channelssend / receive messages
state
model forstatemanagement
Concurrency
Concurrencyoutside
Concurrencyinside
single process
connect / disconnect serversjoin / part channelssend / receive messages
events
event queue
event loop
event handlers
(non)blocking
Example: Gtk
Example: Gtk
<strong>POE</strong>
<strong>POE</strong>“portable multitasking and networkingframework for any event loop”
<strong>POE</strong>1998
<strong>POE</strong>::Session
<strong>POE</strong>::Kernel
<strong>POE</strong>::Component
<strong>POE</strong>::Wheel
<strong>POE</strong>::Filter
<strong>POE</strong>::Session
sleep sort
single threadedsleep sort
use <strong>POE</strong>;<strong>POE</strong>::Session->create(inline_states => {_start => sub {$_[KERNEL]->delay_add(ding => $_, $_)foreach @ARGV;},ding => sub {print "$_[ARG0]\n";}});
# We create a new PoCo-IRC objectmy $irc = <strong>POE</strong>::Component::IRC->spawn(nick => $nickname,ircname => $ircname,server => $server,) or die "Oh noooo! $!";<strong>POE</strong>::Session->create(package_states => [main => [qw(_default _start irc_001 irc_public)],],heap => { irc => $irc },);# $poe_kernel provided by <strong>POE</strong>::Kernel$poe_kernel->run();
package MyBot;use base 'Bot::BasicBot';sub said {my ($self, $msg) = @_;return “You said: $msg->{body}”;}1;
no magic
convention
<strong>Coro</strong>“the only real threads in perl”
<strong>Coro</strong>2001
use <strong>Coro</strong>;use <strong>Coro</strong>::Timer qw(sleep);for my $i (@ARGV) {async {sleep $i;print "> $i\n"}}schedule()
almost completelymagic
not an eventmanager so much
inversionofcontrol
less callbacks
<strong>AnyEvent</strong>
<strong>AnyEvent</strong>“the DBI of event loop programming”
<strong>AnyEvent</strong>2005
use EV;use AE;my @w;for my $i (@ARGV) {push @w, AE::timer $i, 0,sub { print "> $i\n" }}EV::loop
use <strong>AnyEvent</strong>::IRC::Client;my $con = <strong>AnyEvent</strong>::IRC::Client->new;$con->reg_cb(publicmsg => sub {my ($self, $channel, $ircmsg) = @_;$self->send_srv(PRIVMSG => $channel,"You said $ircmsg->{params}[1]");});$con->connect('irc.perl.org', 6667,{ nick => 'dcpmbot' });$con->send_srv(JOIN => '#dc.pm');# START LOOPING FOREVER<strong>AnyEvent</strong>->condvar->recv;
Mixed Magic?
<strong>Reflex</strong>
<strong>Reflex</strong>“Class library for flexible, reactive programs.”
<strong>Reflex</strong>2009
use <strong>Reflex</strong>::Timeout;my @timeouts;foreach my $num (@ARGV) {push @timeouts, <strong>Reflex</strong>::Timeout->new(delay => $num, on_done => sub {print "> $num\n"});}<strong>Reflex</strong>->run_all();
use EV;use AE;my @w;for my $i (@ARGV) {push @w, AE::timer $i, 0,sub { print "> $i\n" }}EV::loop
{package App;use Moose;extends '<strong>Reflex</strong>::Base';use <strong>Reflex</strong>::Interval;use <strong>Reflex</strong>::Trait::Observed;observes ticker => (isa => '<strong>Reflex</strong>::Interval',setup => { interval => 1, auto_repeat => 1 },);}sub on_ticker_tick {print "tick at ", scalar(localtime), "...\n";}exit App->new()->run_all();
High Level
Moosey Magic
<strong>Reflex</strong><strong>Coro</strong><strong>POE</strong><strong>AnyEvent</strong>Class library for flexible, reactiveprograms.the only real threads in perlportable multitasking and networkingframework for any event loopthe DBI of event loop programming
Conclusion
QuestionsandThoughts
<strong>The</strong> End
OR IS IT?!
<strong>POE</strong>, <strong>Reflex</strong>, <strong>Coro</strong>, <strong>AnyEvent</strong>, ...Brock Wilcoxawwaiid@thelackthereof.orgYAPC::NA 2011