gpt4 book ai didi

web - 使用zef安装模块后如何编辑模块中的源代码?

转载 作者:行者123 更新时间:2023-12-02 14:13:57 25 4
gpt4 key购买 nike

例如,我安装了 Cro模块,当我运行我的简单代码时:

 my %headers = {Authorization => OAuth realm="", oauth_consumer_key="xxxxxxxxxxxxxxxx", oauth_nonce="29515362", oauth_signature="KojMlteEAHlYjMcLc6LFiOwRnJ8%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1525913154", oauth_token="xxxx-xxxxxxxxxxxxxxxxxx", oauth_version="1.0", User-Agent => Cro};

my $resp = await Cro::HTTP::Client.get: 'http://api.fanfou.com/statuses/home_timeline.json',
headers => [
user-agent => 'Cro',
content-type => 'application/json;charset=UTF-8',
|%headers
];

say $resp.header('content-type'); # Output: application/json; charset=utf-8;
my Str $text = await $resp.body-text();

它说“无法解析媒体类型application/json;” charset=utf-8;

Died with the exception:
Could not parse media type 'application/json; charset=utf-8;'
in method parse at /Users/ohmycloud/.perl6/sources/5B710DB8DF7799BC8B40647E4F9945BCB8745B69 (Cro::MediaType) line 74
in method content-type at /Users/ohmycloud/.perl6/sources/427E29691A1F7367C23E3F4FE63E7BDB1C5D7F63 (Cro::HTTP::Message) line 74
in method body-text-encoding at /Users/ohmycloud/.perl6/sources/427E29691A1F7367C23E3F4FE63E7BDB1C5D7F63 (Cro::HTTP::Message) line 83
in block at /Users/ohmycloud/.perl6/sources/F870148C579AB45DEB39F02722B617776C3D6D5F (Cro::MessageWithBody) line 49

看起来application/json; charset=utf8; 不是有效的 content-type,因此我添加一个测试:

use Cro::MediaType;
use Test;

sub parses($media-type, $desc, &checks) {
my $parsed;
lives-ok { $parsed = Cro::MediaType.parse($media-type) }, $desc;
checks($parsed) if $parsed;
}

parses 'application/json; charset=utf-8;', 'application/json media type with charset', {
is .type, 'application', 'Correct type';
is .subtype, 'json', 'Correct subtype';
is .subtype-name, 'json', 'Correct subtype name';
is .tree, '', 'No tree';
is .suffix, '', 'No suffix';
is .Str, 'application/json; charset=utf-8;', 'Stringifies correctly';
};

done-testing;

输出是:

not ok 1 - application/json media type with charset
# Failed test 'application/json media type with charset'
# at cro_media.pl6 line 6
# Could not parse media type 'application/json; charset=utf-8;'
1..1
# Looks like you failed 1 test of 1

源代码似乎位于 /Users/ohmycloud/.perl6/sources/5B710DB8DF7799BC8B40647E4F9945BCB8745B69 文件中,我在 TOP 之后添加 ';'? token :

token TOP { <media-type> ';'? }

保存,然后再次运行我的代码,但错误是一样的。那么如何让改变发挥作用呢?在 Perl 5 中,我可以编辑我的 .pm 模块,但在 Perl 6 中,我不知道该怎么做。

最佳答案

this answer in zef's issues ,他们声明“安装是不可变的”。如果您从源代码下载 Cro,修补它并再次安装,以便您的应用程序选择新版本,这可能是一个更好的选择。

也可能发生“application/json”不承认该字符集声明,或者 ; 后面不应该有空格的情况。但这里的主要问题是安装后不应该编辑模块。

关于web - 使用zef安装模块后如何编辑模块中的源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50264214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com