pod_to_html.pl
demerphq
created: 2006-03-18 06:46:21
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;
 $text
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);

perlmonks.org content © perlmonks.org and demerphq

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03