如何获取字符串中的 Perl POD 并将其打印在页面中?
我有一个 POD 文档。现在,我想将该 POD 转换为已解析的部分,例如用法/描述,并将其放入字符串中。
为什么不使用pod2usage
?
这并不能帮助我获取字符串中的输出,而是 STDOUT/文件中的输出。我强调“将其放入字符串”,因为如果长度超过屏幕长度,我想在“页面”中显示 POD。 pod2usage
不会在页面中打印它们:(
有人能告诉我吗我应该使用哪个模块来实现此目的?
I have a POD document. Now, I want to convert that POD to a parsed section like usage/description and get it in a string.
Why not pod2usage
?
This doesn't help me to get the output in string but in STDOUT/file. I am stressing on the point "getting it in string", because I want to display the POD in "pages" if the length exceeds screen length. pod2usage
doesn't print them in pages :(
Can somebody tell me which module to use for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Pod::Usage,在 pod2usage 手册页底部引用。
Pod::Usage, which is referenced on the bottom of the pod2usage man page.
来自 Pod::Parser 文档:
所以这是完全合法的:
另一方面,请记住,您可以使用反引号捕获任何命令的输出,例如
或
qx{}
为了清楚起见:From the Pod::Parser documentation:
So this is perfectly legal:
On the other hand, remember that you can capture the output of any command using backticks, e.g.
or
qx{}
for clarity:您不必自己完成所有 Pod 解析;大部分工作已经通过 Pod::Simple 完成。您可以编写一个简短的子类来执行您需要的任何操作。我在 Mastering Perl 中有一个章节详细介绍了这些细节,但你也可以看看我的 Pod::Perldoc::TOC 模块查看一个简短的示例。
基本上,您处理 =head1 元素,但跳过不是 SYNOPSIS 的元素。一旦遇到正确的=head1,设置一个标志并处理该部分,直到遇到另一个=head1,此时停止解析。您可以在 =head1 之间执行任何操作,包括附加到变量。
You don't have to do all of the Pod parsing yourself; most of it is done already with Pod::Simple. You can write a short subclass to do whatever you need. I have a chapter in Mastering Perl that goes into the details, but you can also look at my Pod::Perldoc::TOC module to see a short example.
Basically, you handle the =head1 elements, but skip the ones that aren't SYNOPSIS. Once you run into the right =head1, set a flag and process the section until you run into another =head1, at which point you stop parsing. You can do anything you like between the =head1's, including appending to a variable.