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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |