The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Component::IRC::Object - A slightly simpler OO interface to PoCoIRC

SYNOPSIS

  package ElizaBot;
  use Chatbot::Eliza;
  use POE;
  use POE::Component::IRC::Object;
  use base qw(POE::Component::IRC::Object);
  
  BEGIN { $chatbot = Chatbot::Eliza->new(); }
  
  sub irc_001 {
    $_[OBJECT]->join( "#elizabot" );
    print "Joined channel #elizabot\n";
  }
  
  sub irc_public {
    my ($self, $kernel, $who, $where, $msg) = 
      @_[OBJECT, KERNEL, ARG0, ARG1, ARG2];
    
    $msg =~ s/^doctor[:,]?\s+//;
    
    my ($nick, undef) = split(/!/, $who, 2);
    my $channel = $where->[0];
    
    my $response = $chatbot->transform($msg);
    $self->privmsg( $channel, "$nick: $response" );
  }
  
  sub irc_join {
    my ($self, $who, $channel) = 
      @_[OBJECT, ARG0, ARG1];
    
    my ($nick, undef) = split(/!/, $who, 2);
    $self->privmsg( $channel, "$nick: How can I help you?" );
  }
  
  package main;
  use POE;
  
  ElizaBot->new(
    Nick => 'doctor',
    Server => 'grou.ch',
    Port => 6667,
  );
  
  $poe_kernel->run();
  exit(0);

DESCRIPTION

Quite simply, I didn't like the way the module POE::Component::IRC worked. I felt like it required me to do too many things - create a PoCo::IRC instance for each IRC client, and then create a session, and in the _start for the session I was supposed to connect to the server and do all the right things.

For an IRC client that connects to multiple channels from one piece of code this is good. But for me it was too flexible. So I wrote this module.

Oh, and this module also saves you some typing.

Basic usage is to create a subclass of this module. In that subclass define events according to the event names in POE::Component::IRC.

This module has pretty good reconnect code in (i.e. reconnect if we get disconnected by accident, and keep retrying indefinitely). But it will break if you redefine the irc_error, irc_connected, or reconnect methods. So don't do that ;-)

Any methods that you call on the object will be passed through as $kernel-post()> calls to the underlying POE::Component::IRC object. This makes it very easy to return messages, via $self->privmsg($channel, $text) and so on.

BUGS

Probably some. Some may consider it a bug that the whole module uses AUTOLOAD and _default to send calls to the right place.

LICENSE

This is free software. You may use and distribute it under the same terms as perl itself.

AUTHOR

Matt Sergeant - matt@sergeant.org