由于 Perl 的 Net::IRC 库已被弃用,我需要将一些使用它的旧代码转换为较新的 AnyEvent::IRC::Client。问题在于 MetaCPAN 的 AnyEvent 文档。不显示与 IRC 数字事件代码和 Net::IRC 支持的 add_global_handler() 和 add_handler() 方法的任何等价性。因此,例如,AnyEvent::IRC::Client 的语法中的以下 Net::IRC 代码片段等效于什么?非常感谢任何见解。谢谢!
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 ;
AnyEvent::IRC::Client 的文档(参考:https ://metacpan.org/pod/AnyEvent::IRC::Client )仅提供 reg_cb() 方法,没有 IRC 数字代码处理程序,所以以下是我所拥有的到目前为止,新代码:
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 ) ;