NAME

Net::IRC3::Client::Connection - A highlevel IRC connection

SYNOPSIS

use AnyEvent;
use Net::IRC3::Client::Connection;

my $c = AnyEvent->condvar;

my $timer;
my $con = new Net::IRC3::Client::Connection;

$con->reg_cb (registered => sub { print "I'm in!\n"; 0 });
$con->reg_cb (disconnect => sub { print "I'm out!\n"; 0 });
$con->reg_cb (
   sent => sub {
      if ($_[2] eq 'PRIVMSG') {
         print "Sent message!\n";
         $timer = AnyEvent->timer (after => 1, cb => sub { $c->broadcast });
      }
      1
   }
);

$con->send_srv (PRIVMSG => "Hello there i'm the cool Net::IRC3 test script!", 'elmex');

$con->connect ("localhost", 6667);
$con->register (qw/testbot testbot testbot/);

$c->wait;
undef $timer;

$con->disconnect;

DESCRIPTION

Net::IRC3::Client::Connection is a highlevel client connection, that manages all the stuff that noone wants to implement again and again when handling with IRC. For example it PONGs the server or keeps track of the users on a channel.

EVENTS

The following events are emitted by Net::IRC3::Client::Connection. Use reg_cb as described in Net::IRC3::Connection to register to such an event.

registered

Emitted when the connection got successfully registered.

channel_add $channel @nicks

Emitted when @nicks are added to the channel $channel, this happens for example when someone JOINs a channel or when you get a RPL_NAMREPLY (see RFC2812).

channel_remove $channel @nicks

Emitted when @nicks are removed from the channel $channel, happens for example when they PART, QUIT or get KICKed.

join $nick $channel $is_myself

Emitted when $nick enters the channel $channel by JOINing. $is_myself is true if youself are the one who JOINs.

part $nick $channel $is_myself $msg

Emitted when $nick PARTs the channel $channel. $is_myself is true if youself are the one who PARTs. $msg is the PART message.

quit $nick $msg

Emitted when the nickname $nick QUITs with the message $msg.

publicmsg $channel $ircmsg

Emitted for NOTICE and PRIVMSG where the target $channel is a channel. $ircmsg is the original IRC message hash like it is returned by parse_irc_msg.

privatemsg $nick $ircmsg

Emitted for NOTICE and PRIVMSG where the target $nick (most of the time you) is a nick. $ircmsg is the original IRC message hash like it is returned by parse_irc_msg.

METHODS

register ($nick, $user, $real)

Sends the IRC registration commands NICK and USER.

nick ()

Returns the current nickname, under which this connection is registered at the IRC server. It might be different from the one that was passed to register as a nick-collision might happened on login.

channel_list ()

This returns a hash reference. The keys are the currently joined channels. The values are hash references which contain the joined nicks as key.

send_srv ($command, $trailing, @params)

This function sends an IRC message that is constructed by mk_msg (undef, $command, $trailing, @params) (see Net::IRC3::Util). If the connection isn't yet registered (for example if the connection is slow) and hasn't got a welcome (IRC command 001) from the server yet, the IRC message is queued until it gets a welcome.

clear_srv_queue

Clears the server send queue.

send_chan ($channel, $command, $trailing, @params))

This function sends a message (constructed by mk_msg (undef, $command, $trailing, @params) to the server, like send_srv only that it will queue the messages if it hasn't joined the channel $channel yet. The queued messages will be send once the connection successfully JOINed the $channel.

clear_chan_queue ($channel)

Clears the channel queue of the channel $channel.

EXAMPLES

See samples/netirc3cl and other samples in samples/ for some examples on how to use Net::IRC3::Client::Connection.

AUTHOR

Robin Redeker, <elmex@ta-sa.org>

SEE ALSO

Net::IRC3::Connection

RFC 2812 - Internet Relay Chat: Client Protocol

COPYRIGHT & LICENSE

Copyright 2006 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.