开发者

How can I produce an HTML summary of Perl modules or scripts in a directory?

Is there a tool available that can produce an HTML summary list of perl modules or scripts in a di开发者_开发技巧rectory tree?

Given

 =head1 NAME

 wibble.pl - does wibble actions

I would like to see something like

<a href="docsforwibble">wibble.pl</a> - does wibble actions
<a href="docsforwobble">wobble.pl</a> - does wobble actions


pod2html --recurse --podpath <dirname>

See perldoc pod2html


It is easy to whip one out using Pod::Find from the Pod::Parser distribution.

The script below creates a rudimentary index file for anything it can find under my site/lib/CGI. It is meant as a demonstration. You are probably better off with pod2html, but this script might still be useful.

#!/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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜