#!/usr/bin/perl # Sample program for the ChronicMessages sample. # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! use warnings; use strict; use POE; use ChronicMessages; # Create the message-based Chronic component. # It is done explicitly so we can set an alias. # Otherwise addressing the component would be # troublesome. # # The spawn() method is used for stand-alone # components that don't return objects. ChronicMessages->spawn(Alias => "ticker"); # Create a session to request and handle # recurring events. POE::Session->create( inline_states => { _start => \&setup_session, got_tick => \&handle_tick, }, ); # Set up the session. Request a recurring # timer. sub setup_session { $_[HEAP]->{count} = 0; $_[KERNEL]->post( ticker => start => { Name => "poitier", Event => "got_tick", Interval => 1, }, ); } # Receive and handle a recurring event. Do some # work, and eventually stop when we're done. sub handle_tick { my ($kernel, $heap) = @_[KERNEL, HEAP]; print "Poit #", ++$heap->{count}, "\n"; $kernel->post( ticker => stop => { Name => "poitier", }, ) if $heap->{count} >= 5; } # Run POE's main loop, otherwise nothing would # happen. POE::Kernel->run(); exit;