http://qs1969.pair.com?node_id=537660
Category: miscellaneous
Author/Contact Info Copyright demerphq. This is Free Software: released under the same terms as perl itself.
Description:

This is a simple pod2html.pl emulator that wraps Pod::Simple::HTML. The Pod::Simple classes IMO aren't very well documented. Pod::Simple::HTML has almost nothing in the way of docs, and I havent seen a fully functional perl script that emulates the old TOMC version. So I'm hoping that this node might help fill the gap a little. I know some of you out there will have written almost the same thing so if you think yours is better or has something useful then please do post it.

I haven't tried to emulate the interface of the old pod2html.pl at all, but I might as time goes by.

Usage:

pod_to_html.pl [--css=FILESPEC] [--notoc] [PODFILE [HTMLFILE]] --css: If FILESPEC is 'auto' then tries to find the CSS based on the value of $^X. Currently 'auto' is only useful on Win32 ActiveState perls. If no value is provided and there exists a pod_to_html.css file in the same directory as the script is running from then it defaults to using that. --notoc: Turn off the Table Of Contents at the top. --notitlebars: Turn off the title header and footer lines If PODFILE is omitted reads from STDIN, if HTMLFILE is omitted writes to STDOUT.

use strict;
use warnings;
use Pod::Simple::HTML;
use Getopt::Long;

my $add_titlebars=1; # show title bars?
{
    package Pod_To_HTML;
    use base 'Pod::Simple::HTML';
    # the default doesnt have long enough max_content_length.
    sub run {
        my $self=shift;
        delete $self->{Pod_To_HTML}{title};
        $self->SUPER::run(@_);
    }
    sub get_title       {
        my $self=shift;
        if (!exists $self->{Pod_To_HTML}{title}) {
            $self->{Pod_To_HTML}{title}= $self->_get_titled_section(
                'NAME',
                max_token => 50,
                desperate => 1,
                max_content_length=>256, @_)
            ;
        }
        return $self->{Pod_To_HTML}{title};
    }
    sub get_title_bar_text {
        my $text=shift->get_title();
        ($text= <<"EOFTEXT")=~s/^#\s+//mg; return $text;
<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="block" valign="middle">
<big><strong><span class="block">&nbsp;$text</span></strong></big>
</td></tr>
</table>
EOFTEXT
    }
    sub do_middle {
        my $self=shift;
        my $fh = $self->output_fh;

        my $title_text= $add_titlebars
            ? $self->get_title_bar_text()
            : "";

        print $fh $title_text;
        my $ret= $self->SUPER::do_middle();
        print $fh $title_text;
        $ret
    }
}

my $toc= 1;
(my $css= $0)=~s/\.[^.]+$/.css/;
$css="" if !-e $css;

GetOptions(
    "css=s" => \$css,
    "toc!" => \$toc,
    "titlebars!"=> \$add_titlebars,
) or die <<'END_OF_USAGE';
pod_to_html.pl [--css=FILESPEC] [--notoc] [PODFILE [HTMLFILE]]
  --css: If FILESPEC is 'auto' then tries to find the CSS based
    on the value of $^X. Currently 'auto' is only useful on
    Win32 ActiveState perls. If no value is provided and there
    exists a pod_to_html.css file in the same directory as the
    script is running from then it defaults to using that.
  --notoc: Turn off the Table Of Contents at the top.
  --notitlebars: Turn off the title header and footer lines

If PODFILE is omitted reads from STDIN, if HTMLFILE is omitted
writes to STDOUT.
END_OF_USAGE

if ( $css eq 'auto' ){
    $css="";
    if (   $^O eq 'MSWin32' && $css=~s/\\bin\\perl\.exe$// )
    {
        $css.="/html/Active.css";
        if ( ! -e $css ) {
            $css="";
        }
    }
    warn "Failed to autodetect 'css' location on '$^O' with exe '$^X'\
+n";
}
if ( $css!~m<^[a-z]{3,5}://> ) {
    # assume its a file
    $css=~s!\\!/!g;
    $css= "file://$css";
}

my $parser=Pod_To_HTML->new();
$parser->index(1)
    if $toc;
$parser->html_css($css)
    if $css;
$parser->parse_from_file(@ARGV);
exit(0);