I was trying to be cute by inserting a Python reference whenever possible 
and it masked the real change I made ;). Sorry about that. The real change 
was using an option key name of 'myname' as opposed to 'MyName'.

The hashref that is passed as the value of 'options' in 
POE::Session::create is imported as is, meaing you have a 
$self->[SE_OPTIONS]->{MyName} = 'Tim' in your session after create. 
However, every invocation of POE::Session::option _lower-cases_ the key 
name on both setting and getting. So your program initializes options with 
a 'MyName' but your subsequent:

my $name = $_[SESSION]->option( 'MyName' );

in handler1 is looking for a 'myname' (lower-cased) option internally 
which isn't defined yet hence the "uninitialized value in concat." error . 
Doing this:

$_[SESSION]->option( 'MyName', 'Mud' );

sets a lower-case 'myname' option internally which is why it works for 
handler2.

But like you have figured out you probably are wanting something else 
instead.

It probably still needs to be fixed in POE::Session though.

-
Lance Braswell - + 1 469 357 6112 



Tim Klein <[EMAIL PROTECTED]> 
03/30/2005 06:44 PM

To
poe@perl.org
cc

Subject
Re: Why can't I retrieve this POE session's options?






You mean you can substitute 'Tim the Enchanter' for 'Tim' in my 
program, and it works for you?  It doesn't for me; I get the very 
same output as with 'Tim'.

Tim

>I think it's a bug. In POE::Session options are stored like so:
>
>$self->[SE_OPTIONS] = $params{+CREATE_OPTIONS}
>
>However the processing in POE::Session::option is done with my $flag =
>lc(shift) on both getting and setting.
>
>Using 'myname' => 'Tim the Enchanter' works for instance.
>-
>Lance Braswell - + 1 469 357 6112
>
>>I expected the following short program to print "My name is Tim"
>>followed by "My name is Mud".  Instead, this is the output:
>>
>>My name is
>>Use of uninitialized value in concatenation (.) or string at opt.pl line
>>25.
>>My name is Mud
>>
>>Apparently, the 'MyName' option isn't getting registered properly
>>during the creation of the session.  But when I later set the same
>>option using the option() command, it works fine.
>>
>>Can someone spot what I'm doing wrong, most likely in my create()
>>call?  It's probably something stupid, but I just can't see it.
>>Thanks for any help!
>>
>>Tim
>>
>>------------------------------------
>>
>>#!/usr/bin/perl
>>
>>use warnings;
>>use strict;
>>use POE;
>>
>>POE::Session->create
>>   (
>>    inline_states =>
>>    {
>>        _start => \&startup,
>>        event1 => \&handler1,
>>        event2 => \&handler2,
>>    },
>>    options => { 'MyName' => 'Tim' },
>>   );
>>
>>POE::Kernel->run();
>>
>>
>>sub startup { $_[KERNEL]->yield('event1'); }
>>
>>sub handler1 {
>>     my $name = $_[SESSION]->option( 'MyName' );
>>     print "My name is $name\n";
>>     $_[KERNEL]->yield('event2');
>>}
>>
>>sub handler2 {
>>     $_[SESSION]->option( 'MyName', 'Mud' );
>>     my $name = $_[SESSION]->option( 'MyName' );
>>     print "My name is $name\n";
>>}


Reply via email to