raku - 如何计算模块的 dist 哈希

标签 raku zef

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

最佳答案

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

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);

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

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

关于raku - 如何计算模块的 dist 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005794/

相关文章:

raku - 将函数指针放入 Perl6 NativeCall CStruct

error-handling - 在 CATCH 中失败

class - 是否可以将一个类的代码分发到多个文件?

module - zef 是否识别和处理预发布模块?

gtk3 - Raku:在 Windows 上安装 Gnome::Gtk3

unit-testing - "zef test ."返回的结果与使用 raku -Ilib 运行某些测试不同

operators - 是否可以链接元运算符来计算 Raku 中两个列表的乘积和?

module - 使用 zef 强制安装顺序

raku - 如何将 LEAVE 移相器导出到 use 语句的外部范围