我正在嘗試提取 Perl POD 的一部分,僅此而已。如果我運行以下命令:
use strict;
use warnings;
use Pod::Simple;
use Pod::Text;
=head1 podTest
normal pod
=cut
print "normalPod:\n";
my $writeNormalPod = Pod::Text->new();
$writeNormalPod->parse_from_file(__FILE__);
=pod
all pod
=cut
print "\nallPod:\n";
my $writePod = Pod::Text->new();
$writePod->accept_targets( ('special') );
$writePod->parse_from_file(__FILE__);
=begin special
special pod
=end special
=cut
print "\nspecialPod:\n";
my $writeSpecialPod = Pod::Text->new();
# what to have here?
$writeSpecialPod->parse_from_file(__FILE__);
# in order to print "special pod" and nothing else
然后我得到輸出:
normalPod:
podTest
normal pod
all pod
allPod:
podTest
normal pod
all pod
special pod
specialPod:
我怎樣才能得到special pod而沒有別的?
我嘗試過的事情:
- 不接受的代碼、指令和目標
- 附加代碼(以及 cut、pod 和 whiteline)處理程式
- 網路搜索(充其量,這會顯示如何使用格式名稱)
有沒有一種簡單的方法可以只從 POD 中獲取特定格式,或者我應該自己決議檔案?
uj5u.com熱心網友回復:
我嘗試過的事情:不接受指令
Yes 似乎Pod::Simple不支持不接受的標準指令。如果你試試:
$writePod->unaccept_directives( 'head1' );
它因錯誤訊息而死:
But you must accept "head1" directives -- it's a builtin!
您也許可以通過子類Pod::Text覆寫其輸出方法來解決限制。例如:
p.pl:
BEGIN {
package My::Pod::Text;
use strict;
use warnings;
use parent qw(Pod::Text);
sub cmd_head1 {} #override this to not print head1
sub cmd_para {} #override this to not print paragraphs
$INC{"My/Pod/Text.pm"} = 1;
}
package main;
use feature qw(say);
use strict;
use warnings;
use My::Pod::Text;
=head1 podTest
normal pod
=begin special
special pod
=end special
=cut
my $writePod = My::Pod::Text->new();
$writePod->accept_targets( ('special') );
$writePod->parse_from_file(__FILE__);
僅輸出:
special pod
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435089.html
上一篇:將圖例添加到基于圖的誤差條顏色
下一篇:使用標量參考子程式
