SlideShare uma empresa Scribd logo
1 de 79
Baixar para ler offline
POE
Stefano Rodighiero
  OpenExp 2006
Perl
Object
Environment
       POE - A Perl Object Environment
?
    POE - A Perl Object Environment
Framework

     POE - A Perl Object Environment
Event
driven
    POE - A Perl Object Environment
Multitasking
Cooperativo
       POE - A Perl Object Environment
Single
thread
   POE - A Perl Object Environment
Networking

      POE - A Perl Object Environment
System
administration
        POE - A Perl Object Environment
GUI
  POE - A Perl Object Environment
POE - A Perl Object Environment
Component


  Wheel

            “Architettura”
 Session


 Kernel




                POE - A Perl Object Environment
Component


  Wheel
            Dispatch di eventi
 Session


 Kernel




               POE - A Perl Object Environment
Component


  Wheel
            Risponde agli eventi
 Session


 Kernel




                POE - A Perl Object Environment
Component

            “Plugin” per sessioni,
             incapsula insiemi di
  Wheel
               gestori di eventi
 Session    POE::Wheel::FollowTail
              POE::Wheel::Run
 Kernel




                 POE - A Perl Object Environment
Component


  Wheel            POE::Component::IRC
               POE::Component::Server::TCP
            POE::Component::Server::SimpleHTTP
                        …CPAN…
 Session


 Kernel




                      POE - A Perl Object Environment
POE - A Perl Object Environment
Un programma tipico

• Istanzia una o più sessioni
 • Esplicitamente, eventualmente usando
    delle Wheel
 • Implicitamente, con Componenti già
    pronti
• POE::Kernel->run()

                           POE - A Perl Object Environment
sub POE::Kernel::TRACE_EVENTS() { 1 }




                       POE - A Perl Object Environment
use POE;

     POE - A Perl Object Environment
for ( 1 .. 3 ) {
  POE::Session -> create(
    inline_states => {
      _start => sub { print quot;Start!nquot; },
      _stop => sub { print quot;Stop!nquot; }
    } );
}




                         POE - A Perl Object Environment
POE::Kernel->run();



            POE - A Perl Object Environment
_start

Session



             Kernel




          POE - A Perl Object Environment
_start

    Session

_start =>
  sub {
    print quot;Start!nquot;
                          Kernel
  }




                       POE - A Perl Object Environment
Passaggio di messaggi

            Accoda un evento, da inoltrare
  post()       alla session specificata

            Accoda un evento, da inoltrare
  yield()        alla session stessa

                Invoca - in maniera
            sincrona - un evento per una
  call()
                  sessione specificata


                         POE - A Perl Object Environment
Passaggio di messaggi

post()/yield()




                 POE - A Perl Object Environment
Passaggio di messaggi



call()




             POE - A Perl Object Environment
Comunicazione
 tra sessioni

        POE - A Perl Object Environment
# Sessione Babbo Natale
POE::Session->create(
   inline_states => {
     _start => sub {
       print quot;Oh oh oh!nquot;;
       $poe_kernel->alias_set( quot;Santaquot; );
     },
     lettera => sub {
       print quot;Lettera da quot;
           . $poe_kernel->alias_list( $_[SENDER] );
     }
   }
);


                               POE - A Perl Object Environment
# Sessione Babbo Natale
POE::Session->create(
   inline_states => {
     _start => sub {
       print quot;Oh oh oh!nquot;;
       $poe_kernel->alias_set( quot;Santaquot; );
     },
     lettera => sub {
       print quot;Lettera da quot;
           . $poe_kernel->alias_list( $_[SENDER] );
     }
   }
);


                               POE - A Perl Object Environment
# Sessione Babbo Natale
POE::Session->create(
   inline_states => {
     _start => sub {
       print quot;Oh oh oh!nquot;;
       $poe_kernel->alias_set( quot;Santaquot; );
     },
     lettera => sub {
       print quot;Lettera da quot;
           . $poe_kernel->alias_list( $_[SENDER] );
     }
   }
);


                               POE - A Perl Object Environment
# Sessione Babbo Natale
POE::Session->create(
   inline_states => {
     _start => sub {
       print quot;Oh oh oh!nquot;;
       $poe_kernel->alias_set( quot;Santaquot; );
     },
     lettera => sub {
       print quot;Lettera da quot;
           . $poe_kernel->alias_list( $_[SENDER] );
     }
   }
);


                               POE - A Perl Object Environment
# Sessione bimbo
POE::Session->create(
   inline_states => {
     _start => sub {
       $poe_kernel->alias_set( quot;Paolinoquot; );
       $poe_kernel->post( quot;Santaquot; => 'lettera' );
     },
   }
);




                              POE - A Perl Object Environment
# Sessione bimbo
POE::Session->create(
   inline_states => {
     _start => sub {
       $poe_kernel->alias_set( quot;Paolinoquot; );
       $poe_kernel->post( quot;Santaquot; => 'lettera' );
     },
   }
);




                              POE - A Perl Object Environment
Babbo Natale       _start




                                Kernel
Paolino
                         _start




                          POE - A Perl Object Environment
Babbo Natale




                               Kernel
Paolino



      post( quot;Santaquot;, quot;letteraquot; )


                         POE - A Perl Object Environment
lettera
          Babbo Natale




                               Kernel
Paolino




                         POE - A Perl Object Environment
lettera
           Babbo Natale
lettera




                                 Kernel
 Paolino



          post( quot;Santaquot;, quot;letteraquot; )


                           POE - A Perl Object Environment
POE - A Perl Object Environment
Wheel
   POE - A Perl Object Environment
Insiemi di
gestori di
  eventi
       POE - A Perl Object Environment
POE::
 Wheel::
FollowTail
      POE - A Perl Object Environment
use POE qw(
	

Wheel::FollowTail
);


              POE - A Perl Object Environment
$|++

   POE - A Perl Object Environment
POE::Session-create(
  inline_states = {...



              POE - A Perl Object Environment
_start = sub {
  my $heap = $_[ HEAP ];
  my $watcher = POE::Wheel::FollowTail-new(
     Filename     = 'logfile.log',
     PollInterval = 1,
     InputEvent   = 'input_state'
  );
  $heap-{ watcher } = $watcher;
} , ...



                           POE - A Perl Object Environment
_start = sub {
  my $heap = $_[ HEAP ];
  my $watcher = POE::Wheel::FollowTail-new(
     Filename     = 'logfile.log',
     PollInterval = 1,
     InputEvent   = 'input_state'
  );
  $heap-{ watcher } = $watcher;
} , ...



                           POE - A Perl Object Environment
_start = sub {
  my $heap = $_[ HEAP ];
  my $watcher = POE::Wheel::FollowTail-new(
     Filename     = 'logfile.log',
     PollInterval = 1,
     InputEvent   = 'input_state'
  );
  $heap-{ watcher } = $watcher;
} , ...



                           POE - A Perl Object Environment
_start = sub {
  my $heap = $_[ HEAP ];
  my $watcher = POE::Wheel::FollowTail-new(
     Filename     = 'logfile.log',
     PollInterval = 1,
     InputEvent   = 'input_state'
  );
  $heap-{ watcher } = $watcher;
} , ...



                           POE - A Perl Object Environment
_start = sub {
  my $heap = $_[ HEAP ];
  my $watcher = POE::Wheel::FollowTail-new(
     Filename     = 'logfile.log',
     PollInterval = 1,
     InputEvent   = 'input_state'
  );
  $heap-{ watcher } = $watcher;
} , ...



                           POE - A Perl Object Environment
input_state = sub {
  my $input = $_[ ARG0 ];
  print $input;
}



                POE - A Perl Object Environment
Session
__________
__________
__________
__________
__________
__________
             Wheel




                POE - A Perl Object Environment
Session
__________
__________
__________
                             input_event
__________
__________
__________
             Wheel




                POE - A Perl Object Environment
POE - A Perl Object Environment
POE
+ Test
+ IRC
    POE - A Perl Object Environment
Testing?
     POE - A Perl Object Environment
Failed 3/10
           tests


                 ?
Test                             IRC




                     POE - A Perl Object Environment
09:41  Quinn larsen: Avast!
               Whoreson swab!
               You failed 3/10 tests!




                       POE - A Perl Object Environment
?
Test                   IRC




           POE - A Perl Object Environment
Session

               POE::
              Wheel::
__________   FollowTail
__________
__________
__________
__________
__________




               POE::
             Component::
                IRC




                           POE - A Perl Object Environment
POE::
Component::
    IRC
       POE - A Perl Object Environment
use POE qw/ Wheel::FollowTail
             Component::IRC
          /;




                  POE - A Perl Object Environment
use Acme::Scurvy::Whoreson::BilgeRat;




                       POE - A Perl Object Environment
my $conf = {
    nick     = 'Quinn',
    ircname = 'HAR!',
    server = 'irc.freenode.net',
    port     = 6667
};
my $channel = '#scummbar';



                     POE - A Perl Object Environment
my $irc = POE::Component::IRC-spawn( %$conf )
  or die quot;HAR!!! $!quot;;




                              POE - A Perl Object Environment
POE::Session-create(
    package_states = [
        'main' = [ qw(
            _default
            _start
            irc_001
            irc_public
            tell_results
        ) ],
    ],
    heap = { irc = $irc }
);
                  POE - A Perl Object Environment
POE::Session-create(
    package_states = [
        'main' = [ qw(
            _default
            _start
            irc_001
            irc_public
            tell_results
        ) ],
    ],
    heap = { irc = $irc }
);
                  POE - A Perl Object Environment
POE::Session-create(
    package_states = [
        'main' = [ qw(
            _default
            _start
            irc_001
            irc_public
            tell_results
        ) ],
    ],
    heap = { irc = $irc }
);
                  POE - A Perl Object Environment
sub _start {
  my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];

    my $watcher = POE::Wheel::FollowTail-new(
      Filename     = 'tests.log' ,
      PollInterval = 1 ,
      InputEvent   = 'tell_results'
    );

    $heap-{ watcher } = $watcher;

    my $irc_sess = $heap-{irc}-session_id();
    $kernel-post( $irc_sess = register = 'all' );
    $kernel-post( $irc_sess = connect = {} );
    undef;
}

                                     POE - A Perl Object Environment
sub _start {
  my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];

    my $watcher = POE::Wheel::FollowTail-new(
      Filename     = 'tests.log' ,
      PollInterval = 1 ,
      InputEvent   = 'tell_results'
    );

    $heap-{ watcher } = $watcher;

    my $irc_sess = $heap-{irc}-session_id();
    $kernel-post( $irc_sess = register = 'all' );
    $kernel-post( $irc_sess = connect = {} );
    undef;
}

                                     POE - A Perl Object Environment
sub _start {
  my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];

    my $watcher = POE::Wheel::FollowTail-new(
      Filename     = 'tests.log' ,
      PollInterval = 1 ,
      InputEvent   = 'tell_results'
    );

    $heap-{ watcher } = $watcher;

    my $irc_sess = $heap-{irc}-session_id();
    $kernel-post( $irc_sess = register = 'all' );
    $kernel-post( $irc_sess = connect = {} );
    undef;
}

                                     POE - A Perl Object Environment
sub irc_001 {
    my ( $kernel, $sender ) =
      @_[ KERNEL, SENDER ];

    $kernel-post(
      $sender = join = $channel );
    undef;
}



                       POE - A Perl Object Environment
sub tell_results
{
  my $kernel         =   $_[KERNEL];
  my $heap           =   $_[HEAP];
  my $line           =   $_[ARG0];
  my $irc_session    =   $heap-{irc};

    my ($failed, $total) = split qr|/|, $line;

    if ($failed) {
      my $insult = Acme::Scurvy::Whoreson::BilgeRat-new(
         language = 'pirate'
      );

        $kernel-post(
          $irc_session = privmsg =
            $channel = quot;$insult! You failed $failed tests!quot; );
        }
    }
}

                                          POE - A Perl Object Environment
sub tell_results
{
  my $kernel         =   $_[KERNEL];
  my $heap           =   $_[HEAP];
  my $line           =   $_[ARG0];
  my $irc_session    =   $heap-{irc};

    my ($failed, $total) = split qr|/|, $line;

    if ($failed) {
      my $insult = Acme::Scurvy::Whoreson::BilgeRat-new(
         language = 'pirate'
      );

        $kernel-post(
          $irc_session = privmsg =
            $channel = quot;$insult! You failed $failed tests!quot; );
        }
    }
}

                                          POE - A Perl Object Environment
sub tell_results
{
  my $kernel         =   $_[KERNEL];
  my $heap           =   $_[HEAP];
  my $line           =   $_[ARG0];
  my $irc_session    =   $heap-{irc};

    my ($failed, $total) = split qr|/|, $line;

    if ($failed) {
      my $insult = Acme::Scurvy::Whoreson::BilgeRat-new(
         language = 'pirate'
      );

        $kernel-post(
          $irc_session = privmsg =
            $channel = quot;$insult! You failed $failed tests!quot; );
        }
    }
}

                                          POE - A Perl Object Environment
POE - A Perl Object Environment
• irc.freenode.net,#poe
• http://poe.perl.org
• “Advanced Perl
  Programming” (O’Reilly) - Cap.7
• http://del.icio.us/slr/poe               ☺


                        POE - A Perl Object Environment
• http://www.perl.it
• irc.freenode.net,#perl.it
• mongers@perl.it


                   POE - A Perl Object Environment
Grazie!
Stefano Rodighiero
  larsen@perl.it

Mais conteúdo relacionado

Mais procurados

YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
Thiago Rondon
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
Andrew Shitov
 

Mais procurados (20)

Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner) Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Troubleshooting Puppet
Troubleshooting PuppetTroubleshooting Puppet
Troubleshooting Puppet
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 

Semelhante a POE

The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
Fabien Potencier
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
lestrrat
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
Carlos Sanchez
 

Semelhante a POE (20)

The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Tutorial Puppet
Tutorial PuppetTutorial Puppet
Tutorial Puppet
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
effective_r27
effective_r27effective_r27
effective_r27
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
Os Treat
Os TreatOs Treat
Os Treat
 
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10
 
Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 

Mais de Stefano Rodighiero (8)

Perl101 - Italian Perl Workshop 2011
Perl101 - Italian Perl Workshop 2011Perl101 - Italian Perl Workshop 2011
Perl101 - Italian Perl Workshop 2011
 
On the most excellent theory of time travel, poetic revolutions, and dynamic ...
On the most excellent theory of time travel, poetic revolutions, and dynamic ...On the most excellent theory of time travel, poetic revolutions, and dynamic ...
On the most excellent theory of time travel, poetic revolutions, and dynamic ...
 
Perl101
Perl101Perl101
Perl101
 
Perl Template Toolkit
Perl Template ToolkitPerl Template Toolkit
Perl Template Toolkit
 
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni WebTest Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
 
Hacking Movable Type
Hacking Movable TypeHacking Movable Type
Hacking Movable Type
 
Perl, musica automagica
Perl, musica automagicaPerl, musica automagica
Perl, musica automagica
 
Scatole Nere
Scatole NereScatole Nere
Scatole Nere
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

POE

  • 2. Perl Object Environment POE - A Perl Object Environment
  • 3. ? POE - A Perl Object Environment
  • 4. Framework POE - A Perl Object Environment
  • 5. Event driven POE - A Perl Object Environment
  • 6. Multitasking Cooperativo POE - A Perl Object Environment
  • 7. Single thread POE - A Perl Object Environment
  • 8. Networking POE - A Perl Object Environment
  • 9. System administration POE - A Perl Object Environment
  • 10. GUI POE - A Perl Object Environment
  • 11. POE - A Perl Object Environment
  • 12. Component Wheel “Architettura” Session Kernel POE - A Perl Object Environment
  • 13. Component Wheel Dispatch di eventi Session Kernel POE - A Perl Object Environment
  • 14. Component Wheel Risponde agli eventi Session Kernel POE - A Perl Object Environment
  • 15. Component “Plugin” per sessioni, incapsula insiemi di Wheel gestori di eventi Session POE::Wheel::FollowTail POE::Wheel::Run Kernel POE - A Perl Object Environment
  • 16. Component Wheel POE::Component::IRC POE::Component::Server::TCP POE::Component::Server::SimpleHTTP …CPAN… Session Kernel POE - A Perl Object Environment
  • 17. POE - A Perl Object Environment
  • 18. Un programma tipico • Istanzia una o più sessioni • Esplicitamente, eventualmente usando delle Wheel • Implicitamente, con Componenti già pronti • POE::Kernel->run() POE - A Perl Object Environment
  • 19. sub POE::Kernel::TRACE_EVENTS() { 1 } POE - A Perl Object Environment
  • 20. use POE; POE - A Perl Object Environment
  • 21. for ( 1 .. 3 ) { POE::Session -> create( inline_states => { _start => sub { print quot;Start!nquot; }, _stop => sub { print quot;Stop!nquot; } } ); } POE - A Perl Object Environment
  • 22. POE::Kernel->run(); POE - A Perl Object Environment
  • 23. _start Session Kernel POE - A Perl Object Environment
  • 24. _start Session _start => sub { print quot;Start!nquot; Kernel } POE - A Perl Object Environment
  • 25. Passaggio di messaggi Accoda un evento, da inoltrare post() alla session specificata Accoda un evento, da inoltrare yield() alla session stessa Invoca - in maniera sincrona - un evento per una call() sessione specificata POE - A Perl Object Environment
  • 26. Passaggio di messaggi post()/yield() POE - A Perl Object Environment
  • 27. Passaggio di messaggi call() POE - A Perl Object Environment
  • 28. Comunicazione tra sessioni POE - A Perl Object Environment
  • 29. # Sessione Babbo Natale POE::Session->create( inline_states => { _start => sub { print quot;Oh oh oh!nquot;; $poe_kernel->alias_set( quot;Santaquot; ); }, lettera => sub { print quot;Lettera da quot; . $poe_kernel->alias_list( $_[SENDER] ); } } ); POE - A Perl Object Environment
  • 30. # Sessione Babbo Natale POE::Session->create( inline_states => { _start => sub { print quot;Oh oh oh!nquot;; $poe_kernel->alias_set( quot;Santaquot; ); }, lettera => sub { print quot;Lettera da quot; . $poe_kernel->alias_list( $_[SENDER] ); } } ); POE - A Perl Object Environment
  • 31. # Sessione Babbo Natale POE::Session->create( inline_states => { _start => sub { print quot;Oh oh oh!nquot;; $poe_kernel->alias_set( quot;Santaquot; ); }, lettera => sub { print quot;Lettera da quot; . $poe_kernel->alias_list( $_[SENDER] ); } } ); POE - A Perl Object Environment
  • 32. # Sessione Babbo Natale POE::Session->create( inline_states => { _start => sub { print quot;Oh oh oh!nquot;; $poe_kernel->alias_set( quot;Santaquot; ); }, lettera => sub { print quot;Lettera da quot; . $poe_kernel->alias_list( $_[SENDER] ); } } ); POE - A Perl Object Environment
  • 33. # Sessione bimbo POE::Session->create( inline_states => { _start => sub { $poe_kernel->alias_set( quot;Paolinoquot; ); $poe_kernel->post( quot;Santaquot; => 'lettera' ); }, } ); POE - A Perl Object Environment
  • 34. # Sessione bimbo POE::Session->create( inline_states => { _start => sub { $poe_kernel->alias_set( quot;Paolinoquot; ); $poe_kernel->post( quot;Santaquot; => 'lettera' ); }, } ); POE - A Perl Object Environment
  • 35. Babbo Natale _start Kernel Paolino _start POE - A Perl Object Environment
  • 36. Babbo Natale Kernel Paolino post( quot;Santaquot;, quot;letteraquot; ) POE - A Perl Object Environment
  • 37. lettera Babbo Natale Kernel Paolino POE - A Perl Object Environment
  • 38. lettera Babbo Natale lettera Kernel Paolino post( quot;Santaquot;, quot;letteraquot; ) POE - A Perl Object Environment
  • 39. POE - A Perl Object Environment
  • 40. Wheel POE - A Perl Object Environment
  • 41. Insiemi di gestori di eventi POE - A Perl Object Environment
  • 42. POE:: Wheel:: FollowTail POE - A Perl Object Environment
  • 43. use POE qw( Wheel::FollowTail ); POE - A Perl Object Environment
  • 44. $|++ POE - A Perl Object Environment
  • 45. POE::Session-create( inline_states = {... POE - A Perl Object Environment
  • 46. _start = sub { my $heap = $_[ HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'logfile.log', PollInterval = 1, InputEvent = 'input_state' ); $heap-{ watcher } = $watcher; } , ... POE - A Perl Object Environment
  • 47. _start = sub { my $heap = $_[ HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'logfile.log', PollInterval = 1, InputEvent = 'input_state' ); $heap-{ watcher } = $watcher; } , ... POE - A Perl Object Environment
  • 48. _start = sub { my $heap = $_[ HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'logfile.log', PollInterval = 1, InputEvent = 'input_state' ); $heap-{ watcher } = $watcher; } , ... POE - A Perl Object Environment
  • 49. _start = sub { my $heap = $_[ HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'logfile.log', PollInterval = 1, InputEvent = 'input_state' ); $heap-{ watcher } = $watcher; } , ... POE - A Perl Object Environment
  • 50. _start = sub { my $heap = $_[ HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'logfile.log', PollInterval = 1, InputEvent = 'input_state' ); $heap-{ watcher } = $watcher; } , ... POE - A Perl Object Environment
  • 51. input_state = sub { my $input = $_[ ARG0 ]; print $input; } POE - A Perl Object Environment
  • 53. Session __________ __________ __________ input_event __________ __________ __________ Wheel POE - A Perl Object Environment
  • 54. POE - A Perl Object Environment
  • 55. POE + Test + IRC POE - A Perl Object Environment
  • 56. Testing? POE - A Perl Object Environment
  • 57. Failed 3/10 tests ? Test IRC POE - A Perl Object Environment
  • 58. 09:41 Quinn larsen: Avast! Whoreson swab! You failed 3/10 tests! POE - A Perl Object Environment
  • 59. ? Test IRC POE - A Perl Object Environment
  • 60. Session POE:: Wheel:: __________ FollowTail __________ __________ __________ __________ __________ POE:: Component:: IRC POE - A Perl Object Environment
  • 61. POE:: Component:: IRC POE - A Perl Object Environment
  • 62. use POE qw/ Wheel::FollowTail Component::IRC /; POE - A Perl Object Environment
  • 63. use Acme::Scurvy::Whoreson::BilgeRat; POE - A Perl Object Environment
  • 64. my $conf = { nick = 'Quinn', ircname = 'HAR!', server = 'irc.freenode.net', port = 6667 }; my $channel = '#scummbar'; POE - A Perl Object Environment
  • 65. my $irc = POE::Component::IRC-spawn( %$conf ) or die quot;HAR!!! $!quot;; POE - A Perl Object Environment
  • 66. POE::Session-create( package_states = [ 'main' = [ qw( _default _start irc_001 irc_public tell_results ) ], ], heap = { irc = $irc } ); POE - A Perl Object Environment
  • 67. POE::Session-create( package_states = [ 'main' = [ qw( _default _start irc_001 irc_public tell_results ) ], ], heap = { irc = $irc } ); POE - A Perl Object Environment
  • 68. POE::Session-create( package_states = [ 'main' = [ qw( _default _start irc_001 irc_public tell_results ) ], ], heap = { irc = $irc } ); POE - A Perl Object Environment
  • 69. sub _start { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'tests.log' , PollInterval = 1 , InputEvent = 'tell_results' ); $heap-{ watcher } = $watcher; my $irc_sess = $heap-{irc}-session_id(); $kernel-post( $irc_sess = register = 'all' ); $kernel-post( $irc_sess = connect = {} ); undef; } POE - A Perl Object Environment
  • 70. sub _start { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'tests.log' , PollInterval = 1 , InputEvent = 'tell_results' ); $heap-{ watcher } = $watcher; my $irc_sess = $heap-{irc}-session_id(); $kernel-post( $irc_sess = register = 'all' ); $kernel-post( $irc_sess = connect = {} ); undef; } POE - A Perl Object Environment
  • 71. sub _start { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; my $watcher = POE::Wheel::FollowTail-new( Filename = 'tests.log' , PollInterval = 1 , InputEvent = 'tell_results' ); $heap-{ watcher } = $watcher; my $irc_sess = $heap-{irc}-session_id(); $kernel-post( $irc_sess = register = 'all' ); $kernel-post( $irc_sess = connect = {} ); undef; } POE - A Perl Object Environment
  • 72. sub irc_001 { my ( $kernel, $sender ) = @_[ KERNEL, SENDER ]; $kernel-post( $sender = join = $channel ); undef; } POE - A Perl Object Environment
  • 73. sub tell_results { my $kernel = $_[KERNEL]; my $heap = $_[HEAP]; my $line = $_[ARG0]; my $irc_session = $heap-{irc}; my ($failed, $total) = split qr|/|, $line; if ($failed) { my $insult = Acme::Scurvy::Whoreson::BilgeRat-new( language = 'pirate' ); $kernel-post( $irc_session = privmsg = $channel = quot;$insult! You failed $failed tests!quot; ); } } } POE - A Perl Object Environment
  • 74. sub tell_results { my $kernel = $_[KERNEL]; my $heap = $_[HEAP]; my $line = $_[ARG0]; my $irc_session = $heap-{irc}; my ($failed, $total) = split qr|/|, $line; if ($failed) { my $insult = Acme::Scurvy::Whoreson::BilgeRat-new( language = 'pirate' ); $kernel-post( $irc_session = privmsg = $channel = quot;$insult! You failed $failed tests!quot; ); } } } POE - A Perl Object Environment
  • 75. sub tell_results { my $kernel = $_[KERNEL]; my $heap = $_[HEAP]; my $line = $_[ARG0]; my $irc_session = $heap-{irc}; my ($failed, $total) = split qr|/|, $line; if ($failed) { my $insult = Acme::Scurvy::Whoreson::BilgeRat-new( language = 'pirate' ); $kernel-post( $irc_session = privmsg = $channel = quot;$insult! You failed $failed tests!quot; ); } } } POE - A Perl Object Environment
  • 76. POE - A Perl Object Environment
  • 77. • irc.freenode.net,#poe • http://poe.perl.org • “Advanced Perl Programming” (O’Reilly) - Cap.7 • http://del.icio.us/slr/poe ☺ POE - A Perl Object Environment
  • 78. • http://www.perl.it • irc.freenode.net,#perl.it • mongers@perl.it POE - A Perl Object Environment
  • 79. Grazie! Stefano Rodighiero larsen@perl.it