【发布时间】:2021-02-17 21:34:50
【问题描述】:
由于 Perl 的 Net::IRC 库已被弃用,我需要将一些使用它的旧代码转换为较新的 AnyEvent::IRC::Client。问题在于 MetaCPAN 的 AnyEvent 文档。不显示与 IRC 数字事件代码和 Net::IRC 支持的 add_global_handler() 和 add_handler() 方法的任何等效性。那么,例如,在 AnyEvent::IRC::Client 的语法中,以下 Net::IRC 代码 sn-ps 的等价物是什么?非常感谢任何见解。谢谢!
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 ) ;
【问题讨论】:
-
你试过什么?你有什么问题?我们回答具体问题;我们不是软件编写服务。
-
@ikegami,如上所述,我在 AnyEvent::IRC:Client 中找不到任何关于如何处理 IRC 事件数字代码的文档。
-
Thx @toolic,根据示例,看起来我可以使用“irc_
”来处理事件数字代码。但仍然不等同于 Net::IRC 的特定 add_global_handler() VS。 add_handler() 方法。