如何将多个 POD 添加到 Perl 脚本的末尾?
我正在使用 Perl 文档中找到的关于如何使用 Getopt::Long 的教程在脚本中。其中展示了如何使用 Pod::Usage 添加文档,而不必输入所有内容出一个子程序或其他东西。无论如何,在例子中他们有这个;
GetOptions('help|?' => \$help, 'b|backup' => \&backup, d|discover => \&discover, man => \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
我添加了一些我自己的论点。
我知道如何参考文档的第一部分。但是我如何引用pod2usage(2)
所述的第二部分?
当我在第 1 部分末尾的 =cut
之后添加新部分时,当我尝试让它显示它时,我遇到了命令提示符,就像它进入然后退出而不显示部分。我做错了什么吗?
I was working with a tutorial found in the perl documentation about how to use Getopt::Long in a script. In there it shows how to add documentation using Pod::Usage rather then having to type everything out a subroutine or something. Anyhow in the example they have this;
GetOptions('help|?' => \$help, 'b|backup' => \&backup, d|discover => \&discover, man => \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
I added some of my own arguments.
I get how to refer to the first section of documentation. But how do I refer to the second section as stated by pod2usage(2)
?
When I add a new section after the =cut
at the end of section 1, when I try to have it display it I am met with a command prompt, like it went in and then out without show the section. Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要“多个 POD”。
pod2usage
,当调用时,例如pod2usage(1)
,这里1代表退出状态,详细程度隐含为1,所以会打印< code>SYNOPSIS 以及任何标题为OPTIONS
、ARGUMENTS
或OPTIONS AND ARGUMENTS
的部分当调用为
pod2usage(-exitval) 时=> 0, -verbose => 2)
,它将在文本寻呼机中打印整个 POD(与perldoc yourscriptname.pl
的操作相同)并退出与0
。 (请注意,它是-exitval
而不是-exitstatus
)。此处的
Pod::Usage
文档对此进行了详细描述,并且工作原理与描述的一样。您可能会发现
pod2usage
的可选-sections
参数与-verbose => 结合使用对您所描述的内容很有用。 1
,选择您想要显示的内容。You don't need "multiple PODs".
pod2usage
, when called as, e.g.,pod2usage(1)
, here the 1 represents the exit status, and the verbosity level is implied as 1, so it will print theSYNOPSIS
, and any sections titledOPTIONS
,ARGUMENTS
orOPTIONS AND ARGUMENTS
When called as
pod2usage(-exitval => 0, -verbose => 2)
, it will print the entirety of the POD, within your text pager (identical to whatperldoc yourscriptname.pl
would do) and exit with0
. (Note it's-exitval
and not-exitstatus
).It's well-described in the
Pod::Usage
documentation here, and works just as described.You may find the optional
-sections
parameter topod2usage
useful for what you have described, combined with-verbose => 1
, to pick and choose what you wish to display.