在不显式导出的情况下获取模块的Pod [英] Obtaining the Pod of a module without explicitly exporting it

查看:77
本文介绍了在不显式导出的情况下获取模块的Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl 6程序中的文档实际上,使用Pod 6 DSL解析为代码的一部分;这样可以在程序内部以 $=pod 变量. 但是,我希望能够访问该变量,以便从例如测试中对其进行处理.在我为Perl 6降临日历写的这个例子中可以简单地导出为类(在这种情况下为语法)变量:

The documentation in Perl 6 programs, using the Pod 6 DSL, are actually parsed as part of the code; this makes that documentation available, inside the program, as the $=pod variable. However, I'd like to have access to that variable in order to process it from, say, tests. In this example I wrote for the Perl 6 Advent Calendar it's simply exported as a class (grammar, in this case) variable:

our $pod = $=pod[0];

然后我可以通过这种方式使用它:

I can then use it this way:

use Data::Dump;

use MONKEY-SEE-NO-EVAL;

sub MAIN( $module  ) {
    try require ::($module);
    say Dump( $::($module)::pod, :max-recursion(2) );

}

在使用类名和正确的路径调用时可以使用;但是它仍然需要显式导出变量.

This works when called with the name of the class and the correct path; but it still needs the explicit export of the variable.

我在一些代码中看到了可以将precomp存储库用于同一件事(对不起,没有很好的单一来源来解释这些存储库).最终,这一行

I have seen in some code that precomp stores can be used (sorry, no good single-source to explain these ones) for the same thing. Eventually, this line

 return nqp::atkey($handle.unit,'$=pod')[0];

发挥作用,访问由precomp存储代表并包含在$handle.unit中的模块的Pod.事实是,这实际上是较低的级别,使用 nqp::atkey NQP的运算符,而不是perl .

Does the trick, accessing the Pod of a module that is represented by the precomp store and contained in $handle.unit. The thing is that this is actually lower level, using the nqp::atkey operator of NQP, not quite perl.

有很多方法可以做到这一点,因此我可以想到两个不同的可能问题. 1.是否可以通过FQN(以::开头)访问该require d或use d单元的Pod? 2.我们是否可以访问require d或use d单元的precomp句柄,以便我们可以直接调用nqp::atkey?

There are many ways of doing this, so I can think of two different possible questions. 1. Is there a way to access via a FQN (preceded by ::) the Pod of that required or used unit? 2. Do we have access to the precomp handle of a required or used unit so that we can call nqp::atkey directly?

推荐答案

我使用了这种技术(找到更简单的方法)来创建 Module :: Pod (即将发布).查看我的答案: https://stackoverflow.com/a/57247392/332359

I used this technique (finding simpler ways to do it) to create Module::Pod (soon to be published). See my answer: https://stackoverflow.com/a/57247392/332359

这篇关于在不显式导出的情况下获取模块的Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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