You can use POE::Session's "object_states" rather than (or in addition to) "inline_states". The following example will have $object handle three events: "_start" will trigger its handle_start() method, "tick" will call handle_tick() and "tock" will call handle_tock():

my $object = Object->new(); POE::Session->create( object_states => [ $object => { _start => "handle_start", tick => "handle_tick", tock => "handle_tock", }, ], );

Here are their hypothetical handlers. Note that we're using POE::Kernel's delay() method here. delay() is equivalent to what you're doing with alarm():

sub handle_start { $_[KERNEL]->delay( tick => 1, 0 ); }, sub handle_tick { my ($self, $kernel, $count) = @_[OBJECT, KERNEL, ARG0]; print "tick $count\n"; $self->do_other_stuff(); $kernel->delay( tock => 1, $count + 1 ); }, tock => sub { print "tock $_[ARG0]\n"; $_[OBJECT]->do_more_stuff(); $_[KERNEL]->delay( tick => 1, $_[ARG0] + 1 ); },

Important note: OBJECT is a constant that evaluates to $self's position within @_ (almost always zero). If a program executes my $self = shift; it will shift everything in @_ one element closer to zero. All the other constants (such as KERNEL and ARG0) would then be pointing to the wrong values within @_.


In reply to Re: Object Methods with POE::Kernel's alarm? by rcaputo
in thread Object Methods with POE::Kernel's alarm? by dynis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.