如何计算模块的 dist 哈希

Tyi*_*yil 4 zef raku

我在 中安装了 Perl 6 ~/.rakudo-star/rakudo-star-2018.04,使用 LoneStar。当zef安装了一个模块,它被安装到Rakudo Perl 6的目录的子目录。这里有一个名为 的目录perl6/site/resources,它似乎包含所有已安装的文件。如何使用 Perl 6 找出哪个模块包含在哪个文件中?

uge*_*exe 5

如果您想获取将被加载的命名空间的来源,您可以执行以下操作:

my $module-name = 'Test';

# Get a Distribution object which provides an IO interface to its contents
my $compunit         = $*REPO.resolve(CompUnit::DependencySpecification.new(:short-name{$module-name}));
my $distribution     = $compunit.distribution;
my $handle-from-name = $distribution.content($distribution.meta<provides>{$module-name}.keys[0]).open;
say $handle-from-name.slurp(:close);

# Or if we already know the name-path:
my $handle-from-path = $distribution.content("lib/Test.pm6").open;
say $handle-from-path.slurp(:close);
Run Code Online (Sandbox Code Playgroud)

请注意,$compunit.distribution只有当 resolve 从CompUnit::Repository::Installation存储库返回 CompUnit 时才有效。

rakudo@1812是进一步改进这一点的框架,允许查询单个存储库($*REPO.resolve迭代存储库的链接列表以给出结果)并在CompUnit::Repository::Installation和之间统一解析/候选者/等的行为CompUnit::Repository::FileSystem

  • 支持分发内容方法的任何内容都是一个实现细节——它可能由一个文件支持,[socket](https://github.com/ugexe/Perl6-Distribution--Common--Remote/blob/d152ce7ab92794a28856648ba6b177c4130f29ee/t/ 01-basic.t#L8)、从进程管道传输的数据等。您可以通过`$distribution.content($distribution.meta&lt;provides&gt;&lt;Test&gt;.keys[0] ).path` 但您将依赖于我们可能随时更改的未记录/不受支持的行为。 (3认同)