• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
POE
 

POE

on

  • 4,212 views

An introduction to POE, the "Perl Object Environment", a framework for event driven state machines

An introduction to POE, the "Perl Object Environment", a framework for event driven state machines

Statistics

Views

Total Views
4,212
Views on SlideShare
4,178
Embed Views
34

Actions

Likes
3
Downloads
44
Comments
0

3 Embeds 34

http://www.stefanorodighiero.net 26
http://www.slideshare.net 7
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    POE POE Presentation Transcript

    • 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