POE
     Edgar Allan POE... POEtry ... Panel Of Experts ... Parallel Object Executor ... Parcel Out Execution ... Parenthetically Over-
   Engineered ... Parity Of Evil ... Part Of Elephant ... Particles Of Eternity ... Party On, Ebenezer ... Passed Out from Excitement ...
     Pathetically Over-Engineered ... Peace On Earth ... People Of Earth ... Perfect Orange Eater ... Perfectly Oblique Eggplant ...
  Periodically Orbits Earth ... Perl Obfuscation Engine ... Perl Object Environment ... Perl Objects for Enterprises ... Perl Objects for
Events ... Perl On Extasy ... Perl Operating Environment ... Perl Operator Extravaganza ... Perl Over Easy ... Perl Over Ethernet ... Perl
    Overdrive Engine ... Perl, Objects and Events ... Perl: Objectively Excellent ... Perlmud Offers Expansions ... Perpetual Orgone
      Energy ... Persistent Object Environment ... Persnickity Oblong Erudition ... Perversely Oriented Entities ... Philanthropic
Organization Enterprises ... Physician Order Entry ... Piece Of Eden ... Piece Of Eight ... Pigs, Owls, and Elephants ... Piles Of Eugh ...
 Pious Object Excelsior ... Piracy Over Ethernet ... Pissed Off Elephants ... Plain Old English ... Plastic Orbs Everywhere ... Platonic
 Object Engine ... Plenty Of Everything ... Plucky Object Engine ... Poe Oracle Environment ... Poe Organizes Everything ... Poe Over
    Earth ... Point Of Entry ... Polyolester ... Port of Embarkment ... Portal Of Evil ... Possibly Over-Engineered ... Post-Occupancy
Evaluation ... Potatoes Of Eternity ... Potentially Omnipotent Entity ... Pow! Oof! Eek! ... Power Operating Environment ... Power Over
  Ethernet ... Practical Over Extraction ... Practically Overengineered Environment ... Preponderance of Evidence ... Preserve Our
 Essences ... Pretty Obelisk, Excavated ... Pretty Obfuscation Engine ... Pretty Obtuse Engine ... Pretty Odd Environment ... Price Of
   Entity ... Princess On Ecstasy ... Probable Obese Elephant ... Product Of Experts ... Products Of Eccentricity ... Prognosis: Over-
 Engineered ... Program Office Estimate ... Programming Over Easy ... Proliferation Of Events ... Prolifically Over-Eaten ... Purity Of
                                                    Essence ... Purveyor Of Everything ...



                                            YAPC::Brasil::2009
                                             Thiago Rondon
FRAMEWORK
EVENT DRIVEN
MULTITASKING
FORKING &
THREADING ?
AD-HOC EVENTS
DISTRIBUTED
PROGRAMMING
     ::IKC
TESTED SYSTEM
1998-2000.........
GROWING
TOOLBOX
Layer 3    POE::Component

                POE::
                                  Layer 2
          [Wheel,Filter,Driver]


              POE::Session
Layer 1
              POE::Kernel
COMPONENT         POE::Kernel

            Disparador de eventos,
  WHEEL
            POE::Loop::Select

 SESSION    Singleton

            Post & yield
 KERNEL
            Timers
COMPONENT       POE::Session


  WHEEL      Responde aos eventos

            $_[OBJECT]
            $_[SESSION]
 SESSION
            $_[HEAP]
            $_[STATE]
 KERNEL     $_[SENDER]
            $_[ARG0..ARG9]
COMPONENT             POE::Wheel

             “Plugins” para a sessão.
  WHEEL      Encapsular conjuntos de
            manipuladores de eventos.

 SESSION    #Exemplo: POE::Wheel::Run
            #Executa um programa ou um conjunto de
            código em um subprocesso usando fork() e
            troca informações pelo stdin, stdout, stderr.
 KERNEL
COMPONENT   POE::Component

            564 componentes no
  WHEEL     CPAN até ontem.
            (30/Outubro/2009)

 SESSION     POE::Component::IRC,
             POE::Component::Server::Radius
             POE::Component::Server::TCP
             POE::Component::Server::HTTP
             POE::Component::Github
 KERNEL      POE::Component::Jabber
             (...)
ESTUDO DE
  CASOS
“Ping Múltiplo”
use POE;
use POE::Component::Client::Ping;
my @addresses = qw(200.219.201.245
200.219.201.246 200.219.201.247);

POE::Component::Client::Ping->spawn(
    Alias => 'pinger',
    Timeout => 5,                SESSION
);

POE::Session->create(          COMPONENT
    inline_states => {
        _start => &client_start,
        pong => &client_got_pong,
    }
);
sub client_start {
    my ($kernel, $session) =
      @_[KERNEL, SESSION];
    print "Starting to ping hosts.n";

    foreach my $address (@addresses) {
        $kernel->post(
          pinger => ping => pong => $address);
    }
}
sub client_got_pong {
    my ($kernel, $session) = @_[KERNEL, SESSION];
    my $request_packet = $_[ARG0];
    my ($request_packetest_address, $request_timeout, $request_time) =
        @{$request_packet};
    my $response_packet = $_[ARG1];
    my ($response_address, $roundtrip_time, $reply_time) =
        @{$response_packet};

    if (defined $response_address) {
        printf("Pinged %-15.15s - Response from %-15.15s in %6.3fsn",
            $request_address, $response_address, $roundtrip_time);
    }
    else {
        print "Time's up for responses from $request_address.n";
    }
}
KERNEL




$poe_kernel->run();
IRC
#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Component::IRC;

my ($irc) = POE::Component::IRC->spawn();

POE::Session->create(
   inline_states => {
     _start     => &bot_start,
     irc_001    => &on_connect,
     irc_public => &on_public,
   },
);
#!/usr/bin/perl
use warnings;                 COMPONENT
use strict;
use POE;
use POE::Component::IRC;

my ($irc) = POE::Component::IRC->spawn();

POE::Session->create(
   inline_states => {
     _start     => &bot_start,
     irc_001    => &on_connect,
     irc_public => &on_public,
   },
);
#!/usr/bin/perl
use warnings;                      SESSION
use strict;
use POE;
                              COMPONENT
use POE::Component::IRC;

my ($irc) = POE::Component::IRC->spawn();

POE::Session->create(
   inline_states => {
     _start     => &bot_start,
     irc_001    => &on_connect,
     irc_public => &on_public,
   },
);
COMPONENT
sub bot_start {
  $irc->yield(register => "all");
   $irc->yield(
    connect => {
      Nick      => 'maluco_yapc',
      Username => 'maluco',
      Ircname => 'YAPC Brasil 2009',
      Server    => 'irc.perl.org',
      Port      => '6667',
    }
  );
}
COMPONENT




sub on_connect {
  $irc->yield(join => “#yapcbrasil”);
}
KERNEL        COMPONENT

sub on_public {
  my ($kernel, $who, $where, $msg) =
             @_[KERNEL, ARG0, ARG1, ARG2];
  my $nick    = (split /!/, $who)[0];
  my $channel = $where->[0];
  my $ts      = scalar localtime;
  print " [$ts] <$nick:$channel> $msgn";
  if (my ($response) = $msg =~ /^$nick (.+)/) {
    $irc->yield(privmsg => $channel,
                           “estamos aqui.“);
  }
}
KERNEL




$poe_kernel->run();
Rocco Caputo
http://poe.perl.org
Obrigado!
            Thiago Rondon
            thiago@aware.com.br
            http://www.aware.com.br/

YAPC::Brasil 2009, POE

  • 1.
    POE Edgar Allan POE... POEtry ... Panel Of Experts ... Parallel Object Executor ... Parcel Out Execution ... Parenthetically Over- Engineered ... Parity Of Evil ... Part Of Elephant ... Particles Of Eternity ... Party On, Ebenezer ... Passed Out from Excitement ... Pathetically Over-Engineered ... Peace On Earth ... People Of Earth ... Perfect Orange Eater ... Perfectly Oblique Eggplant ... Periodically Orbits Earth ... Perl Obfuscation Engine ... Perl Object Environment ... Perl Objects for Enterprises ... Perl Objects for Events ... Perl On Extasy ... Perl Operating Environment ... Perl Operator Extravaganza ... Perl Over Easy ... Perl Over Ethernet ... Perl Overdrive Engine ... Perl, Objects and Events ... Perl: Objectively Excellent ... Perlmud Offers Expansions ... Perpetual Orgone Energy ... Persistent Object Environment ... Persnickity Oblong Erudition ... Perversely Oriented Entities ... Philanthropic Organization Enterprises ... Physician Order Entry ... Piece Of Eden ... Piece Of Eight ... Pigs, Owls, and Elephants ... Piles Of Eugh ... Pious Object Excelsior ... Piracy Over Ethernet ... Pissed Off Elephants ... Plain Old English ... Plastic Orbs Everywhere ... Platonic Object Engine ... Plenty Of Everything ... Plucky Object Engine ... Poe Oracle Environment ... Poe Organizes Everything ... Poe Over Earth ... Point Of Entry ... Polyolester ... Port of Embarkment ... Portal Of Evil ... Possibly Over-Engineered ... Post-Occupancy Evaluation ... Potatoes Of Eternity ... Potentially Omnipotent Entity ... Pow! Oof! Eek! ... Power Operating Environment ... Power Over Ethernet ... Practical Over Extraction ... Practically Overengineered Environment ... Preponderance of Evidence ... Preserve Our Essences ... Pretty Obelisk, Excavated ... Pretty Obfuscation Engine ... Pretty Obtuse Engine ... Pretty Odd Environment ... Price Of Entity ... Princess On Ecstasy ... Probable Obese Elephant ... Product Of Experts ... Products Of Eccentricity ... Prognosis: Over- Engineered ... Program Office Estimate ... Programming Over Easy ... Proliferation Of Events ... Prolifically Over-Eaten ... Purity Of Essence ... Purveyor Of Everything ... YAPC::Brasil::2009 Thiago Rondon
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
    Layer 3 POE::Component POE:: Layer 2 [Wheel,Filter,Driver] POE::Session Layer 1 POE::Kernel
  • 11.
    COMPONENT POE::Kernel Disparador de eventos, WHEEL POE::Loop::Select SESSION Singleton Post & yield KERNEL Timers
  • 12.
    COMPONENT POE::Session WHEEL Responde aos eventos $_[OBJECT] $_[SESSION] SESSION $_[HEAP] $_[STATE] KERNEL $_[SENDER] $_[ARG0..ARG9]
  • 13.
    COMPONENT POE::Wheel “Plugins” para a sessão. WHEEL Encapsular conjuntos de manipuladores de eventos. SESSION #Exemplo: POE::Wheel::Run #Executa um programa ou um conjunto de código em um subprocesso usando fork() e troca informações pelo stdin, stdout, stderr. KERNEL
  • 14.
    COMPONENT POE::Component 564 componentes no WHEEL CPAN até ontem. (30/Outubro/2009) SESSION POE::Component::IRC, POE::Component::Server::Radius POE::Component::Server::TCP POE::Component::Server::HTTP POE::Component::Github KERNEL POE::Component::Jabber (...)
  • 15.
  • 16.
  • 17.
    use POE; use POE::Component::Client::Ping; my@addresses = qw(200.219.201.245 200.219.201.246 200.219.201.247); POE::Component::Client::Ping->spawn( Alias => 'pinger', Timeout => 5, SESSION ); POE::Session->create( COMPONENT inline_states => { _start => &client_start, pong => &client_got_pong, } );
  • 18.
    sub client_start { my ($kernel, $session) = @_[KERNEL, SESSION]; print "Starting to ping hosts.n"; foreach my $address (@addresses) { $kernel->post( pinger => ping => pong => $address); } }
  • 19.
    sub client_got_pong { my ($kernel, $session) = @_[KERNEL, SESSION]; my $request_packet = $_[ARG0]; my ($request_packetest_address, $request_timeout, $request_time) = @{$request_packet}; my $response_packet = $_[ARG1]; my ($response_address, $roundtrip_time, $reply_time) = @{$response_packet}; if (defined $response_address) { printf("Pinged %-15.15s - Response from %-15.15s in %6.3fsn", $request_address, $response_address, $roundtrip_time); } else { print "Time's up for responses from $request_address.n"; } }
  • 20.
  • 21.
  • 22.
    #!/usr/bin/perl use warnings; use strict; usePOE; use POE::Component::IRC; my ($irc) = POE::Component::IRC->spawn(); POE::Session->create( inline_states => { _start => &bot_start, irc_001 => &on_connect, irc_public => &on_public, }, );
  • 23.
    #!/usr/bin/perl use warnings; COMPONENT use strict; use POE; use POE::Component::IRC; my ($irc) = POE::Component::IRC->spawn(); POE::Session->create( inline_states => { _start => &bot_start, irc_001 => &on_connect, irc_public => &on_public, }, );
  • 24.
    #!/usr/bin/perl use warnings; SESSION use strict; use POE; COMPONENT use POE::Component::IRC; my ($irc) = POE::Component::IRC->spawn(); POE::Session->create( inline_states => { _start => &bot_start, irc_001 => &on_connect, irc_public => &on_public, }, );
  • 25.
    COMPONENT sub bot_start { $irc->yield(register => "all"); $irc->yield( connect => { Nick => 'maluco_yapc', Username => 'maluco', Ircname => 'YAPC Brasil 2009', Server => 'irc.perl.org', Port => '6667', } ); }
  • 26.
    COMPONENT sub on_connect { $irc->yield(join => “#yapcbrasil”); }
  • 27.
    KERNEL COMPONENT sub on_public { my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2]; my $nick = (split /!/, $who)[0]; my $channel = $where->[0]; my $ts = scalar localtime; print " [$ts] <$nick:$channel> $msgn"; if (my ($response) = $msg =~ /^$nick (.+)/) { $irc->yield(privmsg => $channel, “estamos aqui.“); } }
  • 28.
  • 29.
  • 30.
  • 31.
    Obrigado! Thiago Rondon thiago@aware.com.br http://www.aware.com.br/