.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "AnyEvent::IRC::Connection 3pm" .TH AnyEvent::IRC::Connection 3pm "2011-12-01" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" AnyEvent::IRC::Connection \- An IRC connection abstraction .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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 => \*(Aqtestbot\*(Aq); \& $con\->send_msg (USER => \*(Aqtestbot\*(Aq, \*(Aq*\*(Aq, \*(Aq0\*(Aq, \*(Aqtestbot\*(Aq); \& }, \& irc_001 => sub { \& my ($con) = @_; \& print "$_[1]\->{prefix} says I\*(Aqm in the IRC: $_[1]\->{params}\->[\-1]!\en"; \& $c\->broadcast; \& } \& ); \& \& $c\->wait; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The connection class. Here the actual interesting stuff can be done, such as sending and receiving \s-1IRC\s0 messages. And it also handles \&\s-1TCP\s0 connecting and even enabling of \s-1TLS.\s0 .PP Please note that \s-1CTCP\s0 support is available through the functions \&\f(CW\*(C`encode_ctcp\*(C'\fR and \f(CW\*(C`decode_ctcp\*(C'\fR provided by AnyEvent::IRC::Util. .SS "\s-1METHODS\s0" .IX Subsection "METHODS" .ie n .IP "$con = AnyEvent::IRC::Connection\->new ()" 4 .el .IP "\f(CW$con\fR = AnyEvent::IRC::Connection\->new ()" 4 .IX Item "$con = AnyEvent::IRC::Connection->new ()" This constructor doesn't take any arguments. .Sp \&\fB\s-1NOTE:\s0\fR You are free to use the hash member \f(CW\*(C`heap\*(C'\fR (which contains a hash) to store any associated data with this object. For example retry timers or anything else. .Sp You can also access that member via the \f(CW\*(C`heap\*(C'\fR method. .ie n .IP "$con\->connect ($host, $port [, $prepcb_or_timeout])" 4 .el .IP "\f(CW$con\fR\->connect ($host, \f(CW$port\fR [, \f(CW$prepcb_or_timeout\fR])" 4 .IX Item "$con->connect ($host, $port [, $prepcb_or_timeout])" Tries to open a socket to the host \f(CW$host\fR and the port \f(CW$port\fR. If an error occurred it will die (use eval to catch the exception). .Sp If you want to connect via \s-1TLS/SSL\s0 you have to call the \f(CW\*(C`enable_ssl\*(C'\fR method before to enable it. .Sp \&\f(CW$prepcb_or_timeout\fR can either be a callback with the semantics of a prepare callback for the function \f(CW\*(C`tcp_connect\*(C'\fR in AnyEvent::Socket or a simple number which stands for a timeout. .ie n .IP "$con\->enable_ssl ()" 4 .el .IP "\f(CW$con\fR\->enable_ssl ()" 4 .IX Item "$con->enable_ssl ()" This method will enable \s-1SSL\s0 for new connections that are initiated by \f(CW\*(C`connect\*(C'\fR. .ie n .IP "$con\->disconnect ($reason)" 4 .el .IP "\f(CW$con\fR\->disconnect ($reason)" 4 .IX Item "$con->disconnect ($reason)" Unregisters the connection in the main AnyEvent::IRC object, closes the sockets and send a 'disconnect' event with \f(CW$reason\fR as argument. .ie n .IP "$con\->is_connected" 4 .el .IP "\f(CW$con\fR\->is_connected" 4 .IX Item "$con->is_connected" Returns true when this connection is connected. Otherwise false. .ie n .IP "$con\->heap ()" 4 .el .IP "\f(CW$con\fR\->heap ()" 4 .IX Item "$con->heap ()" Returns the hash reference stored in the \f(CW\*(C`heap\*(C'\fR member, that is local to this connection object that lets you store any information you want. .ie n .IP "$con\->send_raw ($ircline)" 4 .el .IP "\f(CW$con\fR\->send_raw ($ircline)" 4 .IX Item "$con->send_raw ($ircline)" This method sends \f(CW$ircline\fR straight to the server without any further processing done. .ie n .IP "$con\->send_msg ($command, @params)" 4 .el .IP "\f(CW$con\fR\->send_msg ($command, \f(CW@params\fR)" 4 .IX Item "$con->send_msg ($command, @params)" This function sends a message to the server. \f(CW@ircmsg\fR is the argument list for \f(CW\*(C`AnyEvent::IRC::Util::mk_msg (undef, $command, @params)\*(C'\fR. .SS "\s-1EVENTS\s0" .IX Subsection "EVENTS" Following events are emitted by this module and shouldn't be emitted from a module user call to \f(CW\*(C`event\*(C'\fR. See also the documents Object::Event about registering event callbacks. .ie n .IP "connect => $error" 4 .el .IP "connect => \f(CW$error\fR" 4 .IX Item "connect => $error" This event is generated when the socket was successfully connected or an error occurred while connecting. The error is given as second argument (\f(CW$error\fR) to the callback then. .ie n .IP "disconnect => $reason" 4 .el .IP "disconnect => \f(CW$reason\fR" 4 .IX Item "disconnect => $reason" This event will be generated if the connection is somehow terminated. It will also be emitted when \f(CW\*(C`disconnect\*(C'\fR is called. The second argument to the callback is \f(CW$reason\fR, a string that contains a clue about why the connection terminated. .Sp If you want to reestablish a connection, call \f(CW\*(C`connect\*(C'\fR again. .ie n .IP "send => $ircmsg" 4 .el .IP "send => \f(CW$ircmsg\fR" 4 .IX Item "send => $ircmsg" Emitted when a message is about to be sent. \f(CW$ircmsg\fR is an array reference to the arguments of \f(CW\*(C`mk_msg\*(C'\fR (see AnyEvent::IRC::Util). You may modify the array reference to change the message or even intercept it completely by calling \f(CW\*(C`stop_event\*(C'\fR (see Object::Event \s-1API\s0): .Sp .Vb 3 \& $con\->reg_cb ( \& send => sub { \& my ($con, $ircmsg) = @_; \& \& if ($ircmsg\->[1] eq \*(AqNOTICE\*(Aq) { \& $con\->stop_event; # prevent any notices from being sent. \& \& } elsif ($ircmsg\->[1] eq \*(AqPRIVMSG\*(Aq) { \& $ircmsg\->[\-1] =~ s/sex/XXX/i; # censor any outgoing private messages. \& } \& } \& ); .Ve .ie n .IP "sent => @ircmsg" 4 .el .IP "sent => \f(CW@ircmsg\fR" 4 .IX Item "sent => @ircmsg" Emitted when a message (\f(CW@ircmsg\fR) was sent to the server. \&\f(CW@ircmsg\fR are the arguments to \f(CW\*(C`AnyEvent::IRC::Util::mk_msg\*(C'\fR. .ie n .IP "irc_* => $msg" 4 .el .IP "irc_* => \f(CW$msg\fR" 4 .IX Item "irc_* => $msg" .PD 0 .ie n .IP "irc_ => $msg" 4 .el .IP "irc_ => \f(CW$msg\fR" 4 .IX Item "irc_ => $msg" .ie n .IP "read => $msg" 4 .el .IP "read => \f(CW$msg\fR" 4 .IX Item "read => $msg" .PD Emitted when a message (\f(CW$msg\fR) was read from the server. \&\f(CW$msg\fR is the hash reference returned by \f(CW\*(C`AnyEvent::IRC::Util::parse_irc_msg\*(C'\fR; .Sp Note: '' stands for the command of the message in (\s-1ASCII\s0) lower case. .IP "buffer_empty" 4 .IX Item "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 \f(CW\*(C`samples/notify\*(C'\fR about a usage example. .Sp Please note that this buffer is \s-1NOT\s0 the queue mentioned in AnyEvent::IRC::Client! .SH "AUTHOR" .IX Header "AUTHOR" Robin Redeker, \f(CW\*(C`\*(C'\fR .SH "SEE ALSO" .IX Header "SEE ALSO" AnyEvent::IRC .PP AnyEvent::IRC::Client .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2006\-2009 Robin Redeker, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.