首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >乳齿象::侦听器:1在/home/sergio/perl5/lib/perl5/Role/EventEmitter.pm第21行

乳齿象::侦听器:1在/home/sergio/perl5/lib/perl5/Role/EventEmitter.pm第21行
EN

Stack Overflow用户
提问于 2019-06-04 10:58:56
回答 1查看 54关注 0票数 0

我从https://metacpan.org/pod/Mastodon::Client复制了以下示例代码,但它无法工作:

代码语言:javascript
复制
#!/usr/bin/env perl
use strict;
use warnings;
use Mastodon::Client;

my $client = Mastodon::Client->new(
    instance=>'mastodon.cloud',
    name=>'Perl watcher',
    client_id=>'<myid>',
    client_secret=>'<mysecret>',
    access_token=>'<mytoken>',
    coerce_entities=>1
) or die "Cannot connect";
my $listener = $client->stream( 'public' );
$listener->on( update => sub {
    my ($listener, $status) = @_;
    printf "%s said: %s\n",
        $status->account->display_name,
        $status->content;
});
$listener->start;

它给出了以下错误:

乳突::侦听器:1在/home/sergio/perl5/lib/perl5/Role/EventEmitter.pm第21行。

这完全发生在$listener->start;行中,但我不知道为什么。

代码语言:javascript
复制
-- Emit error in Mastodon::Listener (0)
Mastodon::Listener: 1 at /home/sergio/perl5/lib/perl5/Role/EventEmitter.pm line 21.

^ ROLE_EVENTEMITTER_DEBUG=1 v -d:Confess mastodon.pl

代码语言:javascript
复制
Mastodon::Listener: 1 at /home/sergio/perl5/lib/perl5/Role/EventEmitter.pm line 21.
    Role::EventEmitter::emit(Mastodon::Listener=HASH(0x55d97ff65e90), "error", 1, "Can't locate IO/Async/SSL.pm in \@INC (you may need to install"..., ARRAY(0x55d980399a10)) called at /home/sergio/perl5/lib/perl5/Mastodon/Listener.pm line 172
    Mastodon::Listener::__ANON__[/home/sergio/perl5/lib/perl5/Mastodon/Listener.pm:173](CODE(0x55d97fdca288), Mastodon::Listener=HASH(0x55d97ff65e90), "error", 1, "Can't locate IO/Async/SSL.pm in \@INC (you may need to install"..., ARRAY(0x55d980399a10)) called at (eval 400)[/home/sergio/perl5/lib/perl5/Class/Method/Modifiers.pm:89] line 1
    Mastodon::Listener::__ANON__[(eval 400)[/home/sergio/perl5/lib/perl5/Class/Method/Modifiers.pm:89]:1](Mastodon::Listener=HASH(0x55d97ff65e90), "error", 1, "Can't locate IO/Async/SSL.pm in \@INC (you may need to install"..., ARRAY(0x55d980399a10)) called at (eval 402)[/home/sergio/perl5/lib/perl5/Class/Method/Modifiers.pm:148] line 2
    Mastodon::Listener::emit(Mastodon::Listener=HASH(0x55d97ff65e90), "error", 1, "Can't locate IO/Async/SSL.pm in \@INC (you may need to install"..., ARRAY(0x55d980399a10)) called at /home/sergio/perl5/lib/perl5/Mastodon/Listener.pm line 86
    Mastodon::Listener::__ANON__[/home/sergio/perl5/lib/perl5/Mastodon/Listener.pm:86](undef, undef, ARRAY(0x55d980399ae8)) called at /home/sergio/perl5/lib/perl5/Mastodon/Listener.pm line 94
    Mastodon::Listener::__ANON__[/home/sergio/perl5/lib/perl5/Mastodon/Listener.pm:94](undef) called at /home/sergio/perl5/lib/perl5/Net/Async/HTTP.pm line 905
    Net::Async::HTTP::__ANON__[/home/sergio/perl5/lib/perl5/Net/Async/HTTP.pm:906]("Can't locate IO/Async/SSL.pm in \@INC (you may need to install"...) called at /home/sergio/perl5/lib/perl5/Future.pm line 1008
    Future::on_fail(Future=HASH(0x55d98037b678), CODE(0x55d98037af88)) called at /home/sergio/perl5/lib/perl5/Net/Async/HTTP.pm line 906
    Net::Async::HTTP::do_request(Net::Async::HTTP=HASH(0x55d97ff65ef0), "uri", "https://mastodon.cloud/api/v1/streaming/public", "headers", HASH(0x55d980399a70), "on_error", CODE(0x55d980399ab8), "on_header", ...) called at /home/sergio/perl5/lib/perl5/Mastodon/Listener.pm line 146
    Mastodon::Listener::start(Mastodon::Listener=HASH(0x55d97ff65e90)) called at mastodon.pl line 21

如果我在错误文件$_[0]第21行中将$_[1]更改为/home/sergio/perl5/lib/perl5/Role/EventEmitter.pm,并安装了缺少的库IO::异步::SSL,则得到:

代码语言:javascript
复制
-- Emit error in Mastodon::Listener (0)
Mastodon::Listener: Error decoding JSON payload: Reference bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ) did not pass type constraint "Bool" (in $args->{"locked"}) at /home/sergio/perl5/lib/perl5/Mastodon/Types.pm line 83
    Reference bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ) did not pass type constraint "Bool" (in $args->{"locked"})
    "Bool" is defined as: (Type::Tiny::XS::Bool($_))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-04 11:20:33

不幸的是,角色::EventEmitter默认隐藏该错误的细节。至少perl -d:Confess在堆栈跟踪中显示了有用的信息。

否则,可以通过注册error处理程序来恢复错误消息:

代码语言:javascript
复制
use Data::Dumper;
...
$listener->on( error => sub {
    my ($is_fatal, $message, $details) = @_;
    die "error ($is_fatal): $message\n" . Dumper($details);
});

实际的错误信息,

代码语言:javascript
复制
Can't locate IO/Async/SSL.pm in @INC (@INC contains: ...)

只意味着您需要安装IO::异步::SSL模块。

... did not pass type constraint "Bool" (in $args->{"locked"}) ...错误看起来像Mastodon问题#10 :Client。有一个补丁,但它还没有进入官方的Mastodon::Client发行版。

一种可能的解决方法可能是将Type::might降到版本1.003002或更低。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56442516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档