如何找到 Perl 6 模块的版本和权限?

How do I find the version and authority of a Perl 6 module?

Bar.pm中,我声明了一个class,权限(作者)和版本:

class Bar:auth<Camelia>:ver<4.8.12> {
    }

如果我在程序中使用它,我如何查看我正在使用的模块版本、谁编写的以及模块加载器如何找到它?一如既往,文档链接很重要。

这个问题也在 perl6-users 上被问到,但在满意的答案(或文档链接)出现之前就死了。

这个问题的另一个问题是许多人没有将该信息添加到他们的 class 或模块定义中。它出现在 META.json 文件中,但没有出现在代码中。

(可能不是一个令人满意的答案,因为事情的事实不是很令人满意,尤其是关于文档的状态,但这里是...)


如果模块或 class 直接在源代码中版本化 class Bar:auth<Camelia>:ver<4.8.12>,那么任何导入它的代码都可以 introspect 它:

use Bar;

say Bar.^ver;   # v4.8.12
say Bar.^auth;  # Camelia

# ...which is short for:
say Bar.HOW.ver(Bar);   # v4.8.12
say Bar.HOW.auth(Bar);  # Camelia

verauth 方法由:

提供

不幸的是,我认为元对象目前没有提供获取 module/class 的源路径的方法。
通过手动执行 userequire 加载编译单元的步骤,您至少可以到达前缀路径 (即来自 $PERL6LIBuse lib-I 等。它是从):

加载的
my $comp-spec = CompUnit::DependencySpecification.new: short-name => 'Bar';
my $comp-unit = $*REPO.resolve: $comp-spec;
my $comp-repo = $comp-unit.repo;
say $comp-repo.path-spec;  # file#/home/smls/dev/lib
say $comp-repo.prefix;     # "/home/smls/dev/lib".IO

$comp-unitCompUnit.
类型的对象 $comp-repoCompUnit::Repository::FileSystem.
这两个文档页面尚不存在,$*REPO 仅在 list of dynamic variables.

中简要提及

如果该模块是您提到的邮件列表线程中正确设置 distribution, you can get at the meta-info defined in its META6.json (as posted by Lloyd Fournier 的一部分):

if try $comp-unit.distribution.meta -> %dist-meta {
    say %dist-meta<ver>;
    say %dist-meta<auth>;
    say %dist-meta<license>;
}