【发布时间】:2016-12-01 09:39:26
【问题描述】:
Perl 6 Plain-Old-Documentation(也许是 Fancy-New-Documentation)有一些特性允许它为它看到的东西构建文档,并且文档在运行时显示在 $=pod 变量中。
但是,当我在程序文本中出错时无法阅读文档,我感到很惊讶。这里我省略了两个语句之间的语句分隔符:
use v6;
BEGIN { put "BEGIN" }
INIT { put "INIT" }
CHECK { put "CHECK" }
"foo" "bar";
DOC INIT { put "DOC INIT" }
DOC BEGIN { put "DOC BEGIN" }
DOC CHECK { put "DOC CHECK" }
=begin pod
=head1 This is a title
This is a bit of pod
=end pod
当我使用--doc 开关运行它时,程序语法很重要(并且BEGIN 运行):
$ perl6 --doc doc.p6
BEGIN
===SORRY!=== Error while compiling ...
Two terms in a row
------> "foo"⏏ "bar";
expecting any of:
infix
infix stopper
statement end
statement modifier
statement modifier loop
当我修复它时,我收到了一些警告(因此,perl6 正在编译)并且编译时阶段器运行:
BEGIN
DOC BEGIN
DOC CHECK
CHECK
WARNINGS for /Users/brian/Desktop/doc.p6:
Useless use of constant string "bar" in sink context (line 9)
Useless use of constant string "foo" in sink context (line 9)
INIT
DOC INIT
This is a title
This is a bit of pod
我们已经知道这在 Perl 5 中有点危险。perl -c 和 BEGIN 块可以运行代码。见How to check if a Perl script doesn't have any compilation errors?。我不认为这比我们已经知道的更危险,但现在它发生在我没有明确要求某些东西来编译程序语句的时候。
我还没有深入研究 Perl 6 pod 的细节,以及为什么在声明符块和 .WHY(一个很酷的功能)之外可能需要这样做,但这似乎会导致麻烦。是否有可能提取 Pod 的外部程序?或者除非程序运行,否则没有声明符的方法?
【问题讨论】:
标签: documentation raku