Re: Better ways than call()

John <[email protected]> Mon, 9 Nov 2015 10:18:23 -0600
Newsgroups gmane.comp.lang.perl.poe
Message-ID <CANUwEq=A=yc8xnNq0cWNT0GrPePDN8vefmC+47=+9stwOPmDwQ@mail.gmail.com>
--001a114428a43d398205241df132
Content-Type: text/plain; charset=UTF-8

Thanks.  That helps a bunch.

John
On Nov 9, 2015 7:47 AM, "Rocco Caputo" <[email protected]> wrote:

> Hi, John.
>
> There's no requirement to store everything in $_[HEAP].  Data that must be
> accessible outside a session can be stored somewhere else.
>
> For example, if you're using object_states to handle events, each call
> gets a reference to the object: $_[OBJECT].  So you can store data
> particular to the object in the object handling events.  Normal accessors
> can be used to access it.  This gets tricky fast since mutators and other
> methods that initiate actions in the underlying session may still involve
> post() or call().  POE::Component::Resolver does the tricky parts, but it
> doesn't do the simpler thing you need.
>
> There could be a shared dictionary for accessible data.  This could be as
> basic as a hash in a scope outside the session.  The %users hash in
> http://poe.perl.org/?POE_Cookbook/Chat_Server is this sort of thing.  I
> prefer something like this when peer sessions must coordinate their work.
>
> External code that requests work from a session can also pass in a
> reference where state will be stored.  This could be a reference to some
> structure both the requester and the worker agree upon.  I prefer to use
> objects for this, since the contract between requester and worker can be
> encoded and enforced in methods.
>
> --
> Rocco Caputo <[email protected]>
>
> > On Nov 9, 2015, at 08:06, john <[email protected]> wrote:
> >
> > The POE::Kernel documentation indicates this for call():
> >
> > call() returns the value returned by the EVENT_NAME handler. It can do
> this because the handler is invoked before call() returns. call() can
> therefore be used as an accessor, although there are better ways to
> accomplish simple accessor behavior.
> >
> > What are some of those ways?  I tried a simple subroutine but don't seem
> to have access to things like the heap.  I guess I could pass those in but
> than things don't seem as simple anymore.
> >
> > John
>
>

--001a114428a43d398205241df132
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">Thanks.=C2=A0 That helps a bunch.</p>
<p dir=3D"ltr">John</p>
<div class=3D"gmail_quote">On Nov 9, 2015 7:47 AM, &quot;Rocco Caputo&quot;=
 &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<=
br type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, John.<br>
<br>
There&#39;s no requirement to store everything in $_[HEAP].=C2=A0 Data that=
 must be accessible outside a session can be stored somewhere else.<br>
<br>
For example, if you&#39;re using object_states to handle events, each call =
gets a reference to the object: $_[OBJECT].=C2=A0 So you can store data par=
ticular to the object in the object handling events.=C2=A0 Normal accessors=
 can be used to access it.=C2=A0 This gets tricky fast since mutators and o=
ther methods that initiate actions in the underlying session may still invo=
lve post() or call().=C2=A0 POE::Component::Resolver does the tricky parts,=
 but it doesn&#39;t do the simpler thing you need.<br>
<br>
There could be a shared dictionary for accessible data.=C2=A0 This could be=
 as basic as a hash in a scope outside the session.=C2=A0 The %users hash i=
n <a href=3D"http://poe.perl.org/?POE_Cookbook/Chat_Server" rel=3D"noreferr=
er" target=3D"_blank">http://poe.perl.org/?POE_Cookbook/Chat_Server</a> is =
this sort of thing.=C2=A0 I prefer something like this when peer sessions m=
ust coordinate their work.<br>
<br>
External code that requests work from a session can also pass in a referenc=
e where state will be stored.=C2=A0 This could be a reference to some struc=
ture both the requester and the worker agree upon.=C2=A0 I prefer to use ob=
jects for this, since the contract between requester and worker can be enco=
ded and enforced in methods.<br>
<br>
--<br>
Rocco Caputo &lt;<a href=3D"mailto:[email protected]">[email protected]</a>=
&gt;<br>
<br>
&gt; On Nov 9, 2015, at 08:06, john &lt;<a href=3D"mailto:[email protected]=
om">[email protected]</a>&gt; wrote:<br>
&gt;<br>
&gt; The POE::Kernel documentation indicates this for call():<br>
&gt;<br>
&gt; call() returns the value returned by the EVENT_NAME handler. It can do=
 this because the handler is invoked before call() returns. call() can ther=
efore be used as an accessor, although there are better ways to accomplish =
simple accessor behavior.<br>
&gt;<br>
&gt; What are some of those ways?=C2=A0 I tried a simple subroutine but don=
&#39;t seem to have access to things like the heap.=C2=A0 I guess I could p=
ass those in but than things don&#39;t seem as simple anymore.<br>
&gt;<br>
&gt; John<br>
<br>
</blockquote></div>

--001a114428a43d398205241df132--