Reputation: 255
Since the Perl's Net::IRC library's been deprecated, I need to convert some old code that uses it over to the newer AnyEvent::IRC::Client. The problem is that the MetaCPAN's AnyEvent docs. don't show any equivalence to the IRC numeric event codes and the add_global_handler() and add_handler() methods that Net::IRC supports. So, for example, what would be the equivalent of the following Net::IRC code snippets in AnyEvent::IRC::Client's syntax? Any insight is greatly appreciated. Thanks!
my $irc = new Net::IRC ;
my $conn = $irc->newconn( Server => ..., Port => ..., Nick => ... ) ;
$conn->add_global_handler( [ 251, 252, 253, 254, 255, 302 ], \&on_init ) ;
$conn->add_global_handler( [ 422, 376 ], \&on_connect ) ;
$conn->add_handler( 'crping', \&on_ping_reply ) ;
$conn->add_handler( 'caction', \&on_action ) ;
...
$irc->start ;
The docs for AnyEvent::IRC::Client ( ref: https://metacpan.org/pod/AnyEvent::IRC::Client ) only provides reg_cb() method and no IRC numeric code handler, so below is all I have so far for the new codes:
my $condVar = AnyEvent->condvar ;
my $conn = AnyEvent::IRC::Client->new() ;
$conn->connect( $server, $port, ... ) ;
$conn->reg_cb( crping => sub { ... } ) ;
$conn->reg_cb( caction => sub { ... } ) ;
my $timer = AnyEvent->timer (
after => $twoSecs ,
cb => sub {
$conn->disconnect ;
$condVar->send ;
}#end callback
) ;#end timer
$condVar->recv ;
undef( $timer ) ;
Upvotes: 2
Views: 107
Reputation: 385917
Your post lacks a clear queston. In fact, your question appears to be in the comments, and it's not even phrased as a question.
I could NOT find any documentation on how to handle IRC's event numeric codes in AnyEvent::IRC:Client
This is supported by the fact that the only part missing from the second snippet appears to be the following:
$conn->add_global_handler( [ 251, 252, 253, 254, 255, 302 ], \&on_init ) ;
$conn->add_global_handler( [ 422, 376 ], \&on_connect ) ;
So I'm assuming you're asking how to handle those events with AnyEvent::IRC::Client.
The source and the samples included in the distribution both suggest you can use the following:
$conn->reg_cb("irc_$_" => \&on_init) for 251..255, 302;
$conn->reg_cb("irc_$_" => \&on_connect) for 376, 422;
If not, you can use the following to discover the appropriate identifier:
$conn->reg_cb(debug_recv => sub {
my ($msg) = @_;
say STDERR "Received irc_" . lc($msg->{command});
});
Upon further study of the code, irc_001
, irc_376
and irc_422
result in the welcome
event being fired, so the following would be a better solution:
$conn->reg_cb("irc_$_" => \&on_init) for 251..255, 302;
$conn->reg_cb(welcome => \&on_connect);
Also note that AnyEvent::IRC::Client already handles ping messages from the server.
Upvotes: 3