是否有可用的工具可以在目录树中生成 perl 模块或脚本的 HTML 摘要列表?
给定
=head1 NAME
wibble.pl - does wibble actions
我想看到类似的东西
<a href="docsforwibble">wibble.pl</a> - does wibble actions
<a href="docsforwobble">wobble.pl</a> - does wobble actions
pod2html --recurse --podpath <dirname>
使用 Pod ::Parser发行版中的Pod::Find很容易抽出一个。
下面的脚本为它可以在我的site/lib/CGI
. 这是一个示范。使用 可能会更好pod2html
,但这个脚本可能仍然有用。
#!/usr/bin/perl
use strict; use warnings;
use autodie;
use File::Spec::Functions qw( canonpath );
use HTML::Template;
use Pod::Find qw(pod_find simplify_name);
use Pod::Select;
my $mod_top = canonpath 'c:/opt/perl/site/lib/CGI';
my $html_top = 'c:/opt/perl/html/site/lib/CGI';
my %pods = pod_find($mod_top);
my @pods;
for my $pod ( sort keys %pods ) {
(my $link = $pod) =~ s/^\Q$mod_top//;
$link =~ s/\.\w+\z//;
$link = "file:///${html_top}${link}.html";
my $name;
{
local *STDOUT;
open STDOUT, '>', \$name;
podselect({-sections => [ 'NAME' ] }, $pod);
}
$name = '' unless defined $name;
$name =~ s/^=head1\s+NAME\s+//;
$name =~ s/\s+\z//;
push @pods, {
POD => $pods{$pod},
NAME => $name,
LINK => $link,
};
}
my $tmpl = HTML::Template->new(scalarref => \ <<EO_TMPL
<!DOCTYPE HTML>
<html>
<head><title>Index of Perl Modules</title></head>
<body>
<h1><TMPL_VAR CATEGORY></h1>
<dl>
<TMPL_LOOP PODS>
<dt><a href="<TMPL_VAR LINK>"><TMPL_VAR POD></a></dt>
<dd><TMPL_VAR NAME></dd>
</TMPL_LOOP>
</ul>
</body>
</html>
EO_TMPL
);
$tmpl->param(
CATEGORY => 'CGI',
PODS => \@pods,
);
$tmpl->output(print_to => \*STDOUT);