Pod-HtmlEasy

 view release on metacpan or  search on metacpan

scripts/pod2indexed_html.pl  view on Meta::CPAN

            ],
        ),
        $html->font_start( size => $FONTSIZE ),
        $html->strong( $html->center($TITLE) ),
        $html->font_end,
        $html->hr,    # Horizontal rule
        $html->p,
        $html->dl_start,
    );

    # Get set up to dump %index_track as links to the docs
    my @tags = sort key_sort keys %{$index_track_ref};
    while ( not length $tags[0] ) { shift @tags; }
    while (@tags) {
        my $tags = get_first( \@tags );
        if ( defined $tags ) { definition($tags); }
    }

    $index_fh->print( $html->dl_end, $html->end_html );
    $index_fh->close();
    return;
}

# Here's where it all begins

# Persistant hashes not updated.
local $SIG{INT} = sub { exit 1; };

# Print it now!
*STDOUT->autoflush();

sub outfile {
    $outfile = shift @ARGV;
    return;
}

sub help {
    pod2usage( -verbose => 2 );
    exit 0;
}

# This is set (magically) by Getopt::Auto
our %options;    ## no critic (ProhibitPackageVars)

if ( exists $options{'--scratch'} ) {
    $scratch = 1;
}

if ( exists $options{'--verbose'} ) {
    $verbose = 1;
}

do_retrieve();

if ( exists $options{'dumpdb'} ) { dumpdb(); exit 0; }

if (@ARGV) { convert_local(); exit 0; }

# Put CSS_ADDON at the end of the css
# 'x' is inappropriate here
my @css = split m{$NL}sxm, Pod::HtmlEasy::Data::css;
push @css, splice @css, -1, 1, $CSS_ADDON; ## no critic (ProhibitMagicNumbers)
write_file( $CSS_FILE, join( qq{$NL}, @css ) . $NL );

if ( not -d $targetdir ) {
    mkdir $targetdir
        or error_print(qq{Unable to create $targetdir})
        or carp q{print fail};
}
if ( not -w $targetdir ) {
    error_print(qq{Unable to write $targetdir}) or carp q{print fail};
}

# Generate a hash (in %pod_convert) of qualifying .pm, .pl and .pod files
# and keep up-to-date the hash of the HTML file state (%HTML_TRACK)

if_verbose(qq{Indexing .pm, .pl and .pod$NL$NL});
find( \&list_pods, @sources );

# Update the %index_track hash taking into account that there may be more
# than one path that maps to a particular name. This is used to find
# the HTML for linking.

if_verbose(qq{${NL}Processing HTML paths$NL$NL});
foreach my $podfile ( values %pod_convert ) {

    # Extract the name of the POD
    my $htmlfile = $html_track_ref->{$podfile};

    # "." marks the beginning of the suffix
    my ($tag) = $podfile =~ m{$PREFIXRE(.*)\.}msx;

    if ( not defined $tag ) {

        # Match didn't work.  Try Plan B.
        my ( $hf, $ht ) = @{$htmlfile};
        print qq{Tag match failure for$NL  $hf$NL}
            or carp q{tag match failed}
            or carp q{print fail};
        my ( $name, $path, $suffix ) = fileparse( $hf, '\.html' );
        $tag = $name;
    }

    # PODs in the pod/ directory of the standard distribution are referred
    # to without the pod:: prefix, so let's just dump it.
    $tag =~ s{^pod/}{}msx;

    # Convert the POD path (Foo/Bar) to a POD name (Foo::Bar)
    $tag =~ s{/}{::}msxg;

    if_verbose(qq{$podfile =>$NL  $htmlfile->[0]$NL});

    # Insert the new reference into the %index_track entry.
    $index_track_ref->{$tag}
        = insert_latest( $index_track_ref->{$tag}, $htmlfile );
}

if_verbose(qq{${NL}Generating HTML$NL$NL});
foreach my $html_file ( keys %pod_convert ) {
    convert_pod( FALSE, $pod_convert{$html_file}, $html_file );
}



( run in 0.975 second using v1.01-cache-2.11-cpan-71847e10f99 )