Home > Archive > PERL POE > June 2005 > How to pass custom parameters to a POE::NFA ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to pass custom parameters to a POE::NFA ?
|
|
| Tim Klein 2005-06-09, 4:01 am |
| As a result of a discussion here a few w s ago (on March 30, in
case you want to retrieve it from the archives), I learned that the
'options' parameter to POE::Session::create is not meant to be used
for "custom" options. For example, the following, even though it may
work, is not proper:
POE::Session->create
(
inline_states => [...],
options => { 'myname' => 'Tim' } <--- my custom option 'myname'
);
Instead, the proper way to pass custom parameters at session creation
time is to use the 'heap' parameter or the 'args' parameter to the
create() command.
OK, so far so good. But what's the proper way to do the same thing
when creating a POE::NFA instead of a POE::Session? The
POE::NFA::spawn command doesn't have a 'heap' (or 'runstate')
parameter or an 'args' parameter. The perldoc says "The spawn()
method currently only accepts inline_states and options." So do I
have to use 'options' after all?
Tim
Dallas, Texas
| |
| Rocco Caputo 2005-06-09, 4:01 am |
| On Tue, May 24, 2005 at 06:15:41PM -0500, Tim Klein wrote:
> As a result of a discussion here a few w s ago (on March 30, in
> case you want to retrieve it from the archives), I learned that the
> 'options' parameter to POE::Session::create is not meant to be used
> for "custom" options. For example, the following, even though it may
> work, is not proper:
>
> POE::Session->create
> (
> inline_states => [...],
> options => { 'myname' => 'Tim' } <--- my custom option 'myname'
> );
>
> Instead, the proper way to pass custom parameters at session creation
> time is to use the 'heap' parameter or the 'args' parameter to the
> create() command.
>
> OK, so far so good. But what's the proper way to do the same thing
> when creating a POE::NFA instead of a POE::Session? The
> POE::NFA::spawn command doesn't have a 'heap' (or 'runstate')
> parameter or an 'args' parameter. The perldoc says "The spawn()
> method currently only accepts inline_states and options." So do I
> have to use 'options' after all?
POE::NFA is not well documented. It seems to be the strange cousin of
POE::Session that people rarely talk about, so time is focused
elsewhere.
The NFA session doesn't have a single _start event, so there's nowhere
for constructor parameters to go. And while it may have many states,
there's no initial state specified in spawn().
So the key to starting a state is partially documented in the
SYNOPSIS:
# Spawn an NFA and enter its initial state.
POE::NFA->spawn(
inline_states => \%states
)->goto_state( $start_state, $start_event );
That spawns a new POE::NFA instance, enters its initial state, and
fires off an event that notifies the session that the state has been
entered.
The next clue in this puzzle is goto_state() itself. Its third and
subsequent parameters are passed as arguments to the $start_event in
the state being entered.
I hope that helps.
--
Rocco Caputo - http://poe.perl.org/
| |
| Tim Klein 2005-06-09, 4:01 am |
| Rocco said:
>The NFA session doesn't have a single _start event, so there's nowhere
>for constructor parameters to go. And while it may have many states,
>there's no initial state specified in spawn().
>
>So the key to starting a state is partially documented in the
>SYNOPSIS:
>
> # Spawn an NFA and enter its initial state.
> POE::NFA->spawn(
> inline_states => \%states
> )->goto_state( $start_state, $start_event );
>
>That spawns a new POE::NFA instance, enters its initial state, and
>fires off an event that notifies the session that the state has been
>entered.
>
>The next clue in this puzzle is goto_state() itself. Its third and
>subsequent parameters are passed as arguments to the $start_event in
>the state being entered.
>
>I hope that helps.
Yes, that does help -- thanks, Rocco!
Tim
|
|
|
|
|