I'm trying to understand what POE is all about. I've been reading the perldoc and the first thing it shows is an example in the SYNOPSYS. For starters I decided to type the code in and see what it does.

use strict; use warnings; use POE; sub handler_start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Session ",$session->ID," has started\n"; $heap->{count} = 0; $kernel->yield('increment') if $heap->{count} < 10; } sub handler_increment { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Session ",$session->ID," counted to ",++$heap->{count},".\n" +; } sub handler_stop { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Session ",$session->ID," has stopped.\n"; } for (1..10) { POE::Session->create( inline_states => { _start => \&handler_start, increment => \&handler_increment, _stop => \&handler_stop, }, ); } POE::Kernel->run();

Here's the output...

Session 2 has started Session 3 has started Session 4 has started Session 5 has started Session 6 has started Session 7 has started Session 8 has started Session 9 has started Session 10 has started Session 11 has started Session 2 counted to 1. Session 2 has stopped. Session 3 counted to 1. Session 3 has stopped. Session 4 counted to 1. Session 4 has stopped. Session 5 counted to 1. Session 5 has stopped. Session 6 counted to 1. Session 6 has stopped. Session 7 counted to 1. Session 7 has stopped. Session 8 counted to 1. Session 8 has stopped. Session 9 counted to 1. Session 9 has stopped. Session 10 counted to 1. Session 10 has stopped. Session 11 counted to 1. Session 11 has stopped.

My question is basically, "what is this code trying to accomplish?"

I'm not understanding the point of the $heap->{count} variable.

It seems to always be 1.

Can anyone help me to understand?


In reply to Trying to understand POE by mifflin

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.