使用zef安装模块后如何在模块中编辑源代码? [英] How to edit the source code in module after installed it using zef?

查看:145
本文介绍了使用zef安装模块后如何在模块中编辑源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For example, I've installed the Cro module, when I run my simple code:

 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;

And it says 'Could not parse media type 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,因此我添加了一个测试:

It seems that application/json; charset=utf8; is not a valid content-type, so I add a test:

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令牌后添加';'?:

the source code seems locate in the /Users/ohmycloud/.perl6/sources/5B710DB8DF7799BC8B40647E4F9945BCB8745B69 file, and I add ';'? after the TOP token:

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

保存,然后再次运行我的代码,但是错误是相同的.那么如何使变更生效呢?在Perl 5中,我只能编辑.pm模块,但是在Perl 6中,我不知道该怎么做.

save, and run my code again, but the error is the same. So how to make the change work? In Perl 5, I can just edit my .pm module, but in Perl 6, I dont't know what to do.

推荐答案

在zef问题中的这个答案中,他们指出安装是不可变的". 如果您从源代码下载Cro,对其进行修补并重新安装,以使您的应用程序选择新版本,则可能是一个更好的选择.

In this answer in zef's issues, they state that "installations are immutable". It's probably a better option if you download Cro from its source, patch it and install again so that your application picks up the new version.

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

It might also happen that 'application/json' does not admit that charset declaration, or that there should be no space behind the ;. But the main issue here is that you shouldn't edit modules once installed.

这篇关于使用zef安装模块后如何在模块中编辑源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆