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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.