How does variable scoping work in a POE session?

元气小坏坏 提交于 2019-12-11 07:49:12

问题


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


回答1:


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"
}


来源:https://stackoverflow.com/questions/1064273/how-does-variable-scoping-work-in-a-poe-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!