#!/usr/bin/perl use strict; use warnings FATAL => 'all'; use File::Find; my $dir = shift || '/home/szabgab/perl/510/lib/5.10.0/'; my %index; podfiles(); find({wanted => \&wanted, no_chdir => 1}, $dir); generate_html(); #use YAML; #YAML::DumpFile('index.yaml', \%index); exit; sub wanted { return if $_ !~ /\.pm$/; (my $file = $_) =~ s/\Q$dir//; return if /CPAN.pm/; # it has X<...> comments that we should deal with... return if m{/Pod/Simple.pm} or m{/Pod/Simple/HTML.pm}; #print "$_\n"; process_file($_, $file); } sub podfiles { my $poddir = "$dir/pod"; opendir my $dh, $poddir or die; while (my $file = readdir $dh) { #next if $file !~ /perldata/; next if $file =~ /perltoc/; next if $file !~ /\.pod$/; process_file("$poddir/$file", $file); } } sub process_file { my ($fullpath, $file) = @_; $file =~ s/(pod|pm)$/html/; open my $fh, '<', $fullpath or die; my $section; my $item; while (my $line = <$fh>) { if ($line =~ /^=head[12]\s+(.*)$/) { $section = $1; } if ($line =~ /^=item\s(\w+)/) { $item = $1; } while ($line =~ /X<([^>]+)>/g) { my $keyword = $1; die "$keyword in $fullpath" if not $section; (my $nospace = $section) =~ s/ /-/g; if ($file =~ /perlfunc/ and $item) { $index{$keyword}{"functions/$item.html"} = ['', $item]; } else { $index{$keyword}{$file} = [$nospace, $section]; } } } } sub generate_html { require Template; my $tt = Template->new(); my $template = get_template(); $tt->process(\$template, {date => scalar localtime, index => \%index}, 'index.html'); local $^I = ''; @ARGV = 'index.html'; while (<>) { s/^\s+//; s/\s+$/\n/; print; } } sub get_template { return <<'END_TMPL'; POD Index

POD Index

Generated on [% date %] from the perl documentation. END_TMPL }