So I decided to write an IRC client because all those others either don't support SOCKS or are too big. I was under the impression it would be a 10-minute project because the lovely POE::Component::IRC did all the work for me, but I've run across a problem. It fails to actually connect to anything, it just sits there. What's the problem? Code follows.
#!/usr/bin/perl
use strict;
use warnings;
use POE::Component::IRC;
use Tk;
use YAML qw( LoadFile );
my $mw = MainWindow->new();
my $chan = $mw->Entry( -width => 10 )->pack();
my $join = $mw->Button( -text => 'Join', -command => sub { join($chan)
+ } )->pack();
my $in = $mw->Entry( -width => 80 )->pack();
$mw->Button( -text => 'Send', -command => sub { enter($in,$chan) } )->
+pack();
my $out = $mw->Text()->pack();
my @arg = %{ LoadFile("config_ircclient.yml") };
my $irc = POE::Component::IRC->spawn( @arg ) || die( "Huh?!\n" );
POE::Session->create(
package_states => [
'main' => [ qw( _default _start irc_001 irc_public irc_msg ) ]
],
heap => {
irc => $irc
}
);
if ( fork() ) {
MainLoop;
}
else {
POE::Kernel->run();
}
sub _start {
my $session = $irc->session_id();
POE::Kernel->post( $session => register => 'all' );
POE::Kernel->post( $session => connect => {} );
sendmsg( "POE is starting.\n" );
undef;
}
sub irc_001 {
sendmsg( "Connected.\n" );
undef;
}
sub irc_public {
my ($kernel,$sender,$who,$where,$what) = @_;
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];
sendmsg( "$channel: $nick: $what\n" );
undef;
}
sub _default {
my ( $event, $args ) = @_;
my @output = ( "$event: " );
foreach my $arg ( @$args ) {
if ( ref($arg) eq 'ARRAY' ) {
push( @output, "[" . join(" ,", @$arg ) . "]" );
}
else {
push ( @output, "'$arg'" );
}
}
sendmsg( join( " ", @output ) . "\n" );
undef;
}
sub irc_msg {
my ( $sender, $msg ) = ( (split(/!/,$_[0]))[0], $_[2] );
sendmsg( "PRIVMSG: $sender: $msg\n" );
undef;
}
sub enter {
$irc->yield( privmsg => $_[1]->get() => $_[0]->get() );
$_[0]->selectionClear();
}
sub sendmsg {
$out->insert( 'end', $_[0] );
print "$_[0]";
}
sub join {
$irc->yield( join => $_[0] );
}