Can anyone explain how variable scoping works within a POE session? What is the proper way to pass state within the session, without impacting other sessions?
Thanks Josh
Can anyone explain how variable scoping works within a POE session? What is the proper way to pass state within the session, without impacting other sessions?
Thanks Josh
Scoping is unaffected by POE.
You can use POE's heap (accessible through $_[HEAP]
) to pass data around between your various handlers.
According to the docs, the heap is distinct between sessions by default, but it is possible to override this so that different sessions share a heap.
sub my_state_handler {
$_[HEAP]{some_data} = 'foo';
$_[KERNEL]->yield('another_handler');
}
sub another_handler {
print $_[HEAP]{some_data}, "\n"; # prints "foo\n"
}