#!/usr/bin/perl # Sample program for the ChronicObject sample. # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! use warnings; use strict; use POE; use ChronicObject; # Start the session that will be using recurring # timer events. POE::Session->create( inline_states => { _start => \&setup_session, got_tick => \&handle_tick, }, ); # Create a new recurring timer object at startup. sub setup_session { $_[HEAP]->{count} = 0; $_[HEAP]->{ticker_obj} = ChronicObject->new( Event => "got_tick", Interval => 1, ); } # Handle a recurring timer event, eventually # stopping when we've done enough work. sub handle_tick { my ($kernel, $heap) = @_[KERNEL, HEAP]; print "Poit #", ++$heap->{count}, "\n"; $heap->{ticker_obj}->stop() if $heap->{count} >= 5; } # Run POE's main loop, otherwise nothing would # happen. POE::Kernel->run(); exit;