Question

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

Was it helpful?

Solution

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"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top