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?

In reply to using POE::Component::IRC by b888

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.