Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

pod_to_html.pl

by demerphq (Chancellor)
on Mar 18, 2006 at 11:46 UTC ( #537660=sourcecode: print w/replies, xml ) Need Help??
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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://537660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-01-23 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?