http://qs321.pair.com?node_id=382697

b888 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings. I'm just starting with POE and found some problems writing code using it. I'm trying to write some kind of bot.
package Connector; use strict; use POE; use POE::Component::IRC; my $id = 0; sub new { my $class = shift; my %params = @_; my $self = bless {}, $class; $params{ALIAS} = sprintf("ib_%06d", ++$id); $params{IRC} = sprintf("i_%06d", $id); POE::Component::IRC::->new( $params{IRC} ); POE::Session->new( _start => \&_start, _connect => \&_connect, irc_001 => \&irc_001, [%params], ); return $self; } sub _start { my ($self, $heap, $kernel) = @_[OBJECT, HEAP, KERNEL]; my (%params) = @_[ARG0..$#_]; $heap = { PARAMS => { NICK => "", CONNECTED => 0, } }; $heap->{PARAMS}{NICK} = $params{Nick} if $params{Nick}; foreach my $key (keys %params){ ($key eq "ALIAS" || $key eq "IRC") ? $heap->{$key} = $params{$key} : $heap->{C_INFO}{$key} = $params{$key}; } $kernel->alias_set( $heap->{ALIAS} ); $kernel->post( $heap->{IRC}, "register", ("all") ); $kernel->yield( "_connect" ); } sub _connect { my ($kernel, $heap) = @_[KERNEL, HEAP]; $kernel->post($heap->{IRC}, "connect", { Nick => $heap->{C_INFO}{"Nick"}, Server => $heap->{C_INFO}{"Server"}, Port => $heap->{C_INFO}{"Port"}, Username => $heap->{C_INFO}{"Username"}, Ircname => $heap->{C_INFO}{"Ircname"} } ); } sub irc_001 { }
The problem is that $heap in &_connect is empty (in &_start all is ok). What is wrong?