print "Generating html docs\n"; use strict; use Pod::Html; use Pod::Find qw/contains_pod/; open MAN, 'MANIFEST' || die $!; our @MANIFEST = (); close MAN; # man2html chdir 'blib' || die $!; htmllify('man1/', 'doc/man1/'); htmllify('lib/', 'doc/man3/'); htmllify('doc/examples/', 'doc/examples/'); for ( map( "doc/man1/$_", get_files('doc/man1/') ), map( "doc/man3/$_", get_files('doc/man3/') ) ) { # /me is cursing pod2html open IN, $_ || die $!; local $/; my $html = ; close IN; $html =~ s## my $m = $1; $m =~ s!/!::!g; ''#ge; $html =~ s#>the (.+?) manpage<#>$1<#g; open OUT, '>', $_ || die $!; print OUT $html; close OUT || die $!; } # compile index.html chdir 'doc' || die $!; make_index( '../../doc/index.html', 'index.html', ['man1', 'Section 1 - user documentation'], ['man3', 'Section 3 - module documentation'], ); chdir '../../'; ## various subroutines ## sub htmllify { my ($from, $to) = @_; $from =~ s#/?$#/#; mkdir $to unless -e $to; print "Scanning $from\n"; foreach my $pod ( map {s/^(\.\/)?$from//; $_} grep /^(\.\/)?$from/, @MANIFEST ) { next unless contains_pod("../$from/$pod"); my $out_file = $pod; $out_file =~ s/(\.\w+)?$/.html/; $out_file =~ s#/#::#g; my @opt = ( "--backlink=Top", "--index", "--css=/docs.css", "--htmldir=doc/", "--libpods=perlfunc:perlvar", "--podpath=../$from:lib", "--infile=../$from/$pod", "--outfile=$to/$out_file", "--recurse", "--quiet", ); open SAVERR, '>&STDERR'; open STDERR, '>/dev/null'; # pod2html trows all kind of ugly warnings eval { pod2html(@opt) }; open STDERR, '>&SAVERR'; die $@ if $@; } } sub make_index { my ($source, $file, @dirs) = @_; # create index my $index = "\n"; for (@dirs) { my ($dir, $title) = @$_; $index .= "\n" . "\n"; for my $file (get_files($dir)) { my $name = $file; $name =~ s/\.\w+$//; my $desc = get_desc("$dir/$file"); $index .= "" . "" . #"". "". "\n"; } } $index .= "
 

$title

 $name $desc
\n"; # write file print "Updating blib/doc/$file\n"; open IN, $source || die "could not read $source"; my $body = join '', (); close IN; $body =~ s//$index/ ; open IN, '>', $file || die "could not write $file"; print IN $body; close IN || die "could not write $file"; } sub get_desc { my $file = shift; my $desc; open IN, $file || die "failed to open $file"; while () { next unless m#(.*?)#; (undef, $desc) = split /\s+-\s+/, $1, 2; last; } close IN; $desc =~ s/^\s+|\s+$//g; return $desc; } sub get_files { my $dir = shift; opendir DIR, $dir || die "could not open dir $dir"; my @f = sort grep {$_ !~ /^\./} readdir DIR; closedir DIR; return @f; }