我试图使用Pod::Text::Termcap将Pod作为文本输出到终端窗口。除了一种使用Pod C<>标记显示代码文本的情况外,它大部分工作得很好。通常,Pod::Text::Termcap以双引号显示代码文本,这很好。但是,如果我编写的代码文本只包含数字或美元符号后面跟着数字,代码文本将不再被引用。例如:
use strict;
use warnings;
use Pod::Text::Termcap;
my $pod_str = '=pod
This is a quoted name C<Peter>. The next text: C<$1> , should also be quoted.
=cut';
my $parser = Pod::Text::Termcap->new();
my $str;
$parser->output_string( \$str );
$parser->parse_string_document( $pod_str );
print $str;产出如下:
这是一个引用的名字“彼得”。下一篇文章:$1,也应该被引用。
发布于 2015-03-14 11:23:16
答案在于Pod::Text->cmd_c,它是拉斯·奥尔贝里( Russ )在2001年写的,基本上没有改变。该函数有一些评论,解释了人们认为不能从引用中获益的地方。
# Apply a whole bunch of messy heuristics to not quote things that don't
# benefit from being quoted. These originally come from Barrie Slaymaker and
# largely duplicate code in Pod::Man.
sub cmd_c {
my ($self, $attrs, $text) = @_;
# A regex that matches the portion of a variable reference that's the
# array or hash index, separated out just because we want to use it in
# several places in the following regex.
my $index = '(?: \[.*\] | \{.*\} )?';
# Check for things that we don't want to quote, and if we find any of
# them, return the string with just a font change and no quoting.
$text =~ m{
^\s*
(?:
( [\'\`\"] ) .* \1 # already quoted
| \` .* \' # `quoted'
| \$+ [\#^]? \S $index # special ($^Foo, $")
| [\$\@%&*]+ \#? [:\'\w]+ $index # plain var or func
| [\$\@%&*]* [:\'\w]+ (?: -> )? \(\s*[^\s,]\s*\) # 0/1-arg func call
| [+-]? ( \d[\d.]* | \.\d+ ) (?: [eE][+-]?\d+ )? # a number
| 0x [a-fA-F\d]+ # a hex constant
)
\s*\z
}xo && return $text;
# If we didn't return, go ahead and quote the text.
return $$self{opt_alt}
? "``$text''"
: "$$self{LQUOTE}$text$$self{RQUOTE}";
}逻辑似乎是,他们不认为有必要引用已经看上去像代码的东西。$variables,function_calls(),数字和代码,已经被引用了。要想得到一个明确的答案,你可以给拉斯发电子邮件。
如果您想了解更多信息,您可以从它们的git存储库收集一些信息,但是提交条目没有说明决策。
commit d374354c961250d1ee23342451713313fd934eda
Author: Russ Allbery <rra@stanford.edu>
Date: Tue Jul 10 10:54:27 2001 +0000
* lib/Pod/Text.pm (seq_c): Add heuristics to decide whether or not
to quote the argument of C<>.
* lib/Pod/Text.pm: Added a LICENSE section to the documentation.https://stackoverflow.com/questions/29048111
复制相似问题