AnyEve...nection(3pm)
π AnyEve...nection β the manual page, but make it make sense π
okay bestie, this is AnyEvent::IRC::Connection from the User Contributed Perl Documentation crew β your girl is about to walk you through it like we're texting at 2am π¦
β¨ NAME β¨
AnyEvent::IRC::Connection β it's an IRC connection abstraction. that's the whole name, no notes, she's serving exactly what she says on the tin π
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste ready, no cap:
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;
likeβ¦ she connects, she says hi, she waits. main character energy fr fr π
π DESCRIPTION π
this is the connection class. this is where the actual interesting stuff happens β sending and receiving IRC messages, that's her. and she also handles TCP connecting, plus she can even enable TLS. multi-talented, we love that for her π
heads up bestie: CTCP support is a whole separate thing β it lives in the functionsencode_ctcpanddecode_ctcp, which are provided byAnyEvent::IRC::Util. not here. don't come for this page about it π
π METHODS π
$con = AnyEvent::IRC::Connection->new ()β this constructor doesn't take any arguments. zero. none. she's low maintenance like that β¨
NOTE: you are free to use the hash member heap (which contains a hash) to store any associated data with this object. like retry timers, or literally anything else you want to keep near her π
you can also access that member via the heap method, iykyk.
$con->connect ($host, $port [, $prepcb_or_timeout])β she tries to open a socket to the host$hostand the port$port. if an error occurred, it will die (so wrap it inevalto catch that exception, bestie, don't let it take you out π).
if you want to connect via TLS/SSL you have to call the enable_ssl method before to enable it. order matters, periodt.
$prepcb_or_timeout can either be a callback with the semantics of a prepare callback for the function tcp_connect in AnyEvent::Socket, or a simple number which stands for a timeout. pick your fighter π«Ά
$con->enable_ssl ()β this method will enable SSL for new connections that are initiated byconnect. sparkle her up π₯$con->disconnect ($reason)β unregisters the connection in the main AnyEvent::IRC object, closes the sockets, and sends a'disconnect'event with$reasonas argument. she's leaving the group chat, gracefully π$con->is_connectedβ returns true when this connection is connected. otherwise false. that's it, that's the whole personality check β$con->heap ()β returns the hash reference stored in theheapmember, which is local to this connection object, and it lets you store any information you want. your little stash π$con->send_raw ($ircline)β this method sends$irclinestraight to the server with no further processing done. raw. unfiltered. she said what she said π$con->send_msg ($command, @params)β this function sends a message to the server.@ircmsgis the argument list forAnyEvent::IRC::Util::mk_msg (undef, $command, @params). that's the whole deal πΈ
π¦ EVENTS π¦
these are the events emitted by this module, and bestie β they shouldn't be emitted from a module user call to event. also go read the documents Object::Event about registering event callbacks, it's required reading, no skipping π
connect => $errorβ this event is generated when the socket was successfully connected, or when an error occurred while connecting. the error is given as second argument ($error) to the callback then. so either she made it, or she's telling you why she didn't πdisconnect => $reasonβ this event will be generated if the connection is somehow terminated. it will also be emitted whendisconnectis 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. she's not gone forever, she just needs a minute π«Ά
send => $ircmsgβ emitted when a message is about to be sent.$ircmsgis an array reference to the arguments ofmk_msg(seeAnyEvent::IRC::Util). you may modify the array reference to change the message, or even intercept it completely by callingstop_event(seeObject::EventAPI):
$con->reg_cb (
send => sub {
my ($con, $ircmsg) = @_;
if ($ircmsg->[1] eq 'NOTICE') {
$con->stop_event; # prevent any notices from being sent.
} elsif ($ircmsg->[1] eq 'PRIVMSG') {
$ircmsg->[-1] =~ s/sex/XXX/i; # censor any outgoing private messages.
}
}
);
look at her filtering her own messages. iconic behavior π₯
sent => @ircmsgβ emitted when a message (@ircmsg) was sent to the server.@ircmsgare the arguments toAnyEvent::IRC::Util::mk_msg. she's delivered β¨irc_* => $msgirc_<lowercase command> => $msgread => $msgβ emitted when a message ($msg) was read from the server.$msgis the hash reference returned byAnyEvent::IRC::Util::parse_irc_msg.
Note: '<lowercase command>' stands for the command of the message in (ASCII) lower case. so like, lowercase. keep it lowercase, bestie π
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 alsosamples/notifyabout a usage example π
Please note that this buffer is NOT the queue mentioned in AnyEvent::IRC::Client! do not confuse the two, they are different girlies, i am begging π
π AUTHOR π
Robin Redeker, "<elmex@ta-sa.org>" β shoutout to Robin, the original icon π
π SEE ALSO π
AnyEvent::IRCAnyEvent::IRC::Client
go read those too, bestie, they're the extended universe π¦
β COPYRIGHT & LICENSE β
Copyright 2006-2009 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.
okay and that's the whole page, no cap. this was perl v5.34.0, dated 2022-06-06, from the User Contributed Perl Documentation besties β love you, go connect to something π
πβ¨
π¦ where this page comes from
- debian bookworm: libanyevent-irc-perl 0.97-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libanyevent-irc-perl 0.97-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libanyevent-irc-perl 0.97-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libanyevent-irc-perl 0.97-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libanyevent-irc-perl 0.97-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms