NAME
AnyEvent::IRC::Connection - An IRC connection abstraction
SYNOPSIS
use AnyEvent;
use AnyEvent::IRC::Connection;
my $c = AnyEvent->condvar;
my $con = new AnyEvent::IRC::Connection;
$con->connect ("localhost", 6667);
$con->reg_cb (
connect => sub {
my ($con) = @_;
$con->send_msg (NICK => 'testbot');
$con->send_msg (USER => 'testbot', '*', '0', 'testbot');
},
irc_001 => sub {
my ($con) = @_;
print "$_[1]->{prefix} says i'm in the IRC: $_[1]->{params}->[-1]!\n";
$c->broadcast;
}
);
$c->wait;
DESCRIPTION
The connection class. Here the actual interesting stuff can be done, such as sending and receiving IRC messages.
Please note that CTCP support is available through the functions encode_ctcp
and decode_ctcp
provided by AnyEvent::IRC::Util.
METHODS
- new
-
This constructor does take no arguments.
- connect ($host, $port)
-
Tries to open a socket to the host
$host
and the port$port
. If an error occurred it will die (use eval to catch the exception). - disconnect ($reason)
-
Unregisters the connection in the main AnyEvent::IRC object, closes the sockets and send a 'disconnect' event with
$reason
as argument. - is_connected
-
Returns true when this connection is connected. Otherwise false.
- heap ()
-
Returns a hash reference that is local to this connection object that lets you store any information you want.
- send_raw ($ircline)
-
This method sends
$ircline
straight to the server without any further processing done. - send_msg ($command, @params)
-
This function sends a message to the server.
@ircmsg
is the argument list forAnyEvent::IRC::Util::mk_msg (undef, $command, @params)
.
EVENTS
Following events are emitted by this module and shouldn't be emitted from a module user call to event
. See also the documents Object::Event about registering event callbacks.
- connect
-
This event is generated when the socket was successfully connected or an error occurred while connecting. The error is given as second argument to the callback then.
- disconnect $reason
-
This event will be generated if the connection is somehow terminated. It will also be emitted when
disconnect
is called. The second argument to the callback is$reason
, a string that contains a clue about why the connection terminated.If you want to reestablish a connection, call
connect
again. - sent @ircmsg
-
Emitted when a message (
@ircmsg
) was sent to the server.@ircmsg
are the arguments toAnyEvent::IRC::Util::mk_msg
. - '*' $msg
- read $msg
-
Emitted when a message (
$msg
) was read from the server.$msg
is the hash reference returned byAnyEvent::IRC::Util::parse_irc_msg
; - buffer_empty
-
This event is emitted when the write buffer of the underlying connection is empty and all data has been given to the kernel. See also
samples/notify
about a usage example.Please note that this buffer is NOT the queue mentioned in AnyEvent::IRC::Client!
AUTHOR
Robin Redeker, <elmex@ta-sa.org>
SEE ALSO
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.