Pod-Simple
view release on metacpan or search on metacpan
lib/Pod/Simple/HTMLBatch.pm view on Meta::CPAN
}
sub _do_all_batch_conversions {
my($self, $mod2path, $outdir) = @_;
$self->{"__batch_conv_page_count"} = 0;
foreach my $module (sort {lc($a) cmp lc($b)} keys %$mod2path) {
$self->_do_one_batch_conversion($module, $mod2path, $outdir);
sleep($SLEEPY - 1) if $SLEEPY;
}
return;
}
sub _batch_convert_finish {
my($self, $outdir) = @_;
$self->write_contents_file($outdir);
$self->muse("Done with batch conversion. $$self{'__batch_conv_page_count'} files done.");
$self->muse( "= ", scalar(localtime) );
$self->progress and $self->progress->done("All done!");
return;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub _do_one_batch_conversion {
my($self, $module, $mod2path, $outdir, $outfile) = @_;
my $retval;
my $total = scalar keys %$mod2path;
my $infile = $mod2path->{$module};
my @namelets = grep m/\S/, split "::", $module;
# this can stick around in the contents LoL
my $depth = scalar @namelets;
die "Contentless thingie?! $module $infile" unless @namelets; #sanity
$outfile ||= do {
my @n = @namelets;
$n[-1] .= $HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION;
$self->filespecsys->catfile( $outdir, @n );
};
my $progress = $self->progress;
my $page = $self->html_render_class->new;
if(DEBUG > 5) {
$self->muse($self->{"__batch_conv_page_count"} + 1, "/$total: ",
ref($page), " render ($depth) $module => $outfile");
} elsif(DEBUG > 2) {
$self->muse($self->{"__batch_conv_page_count"} + 1, "/$total: $module => $outfile")
}
# Give each class a chance to init the converter:
$page->batch_mode_page_object_init($self, $module, $infile, $outfile, $depth)
if $page->can('batch_mode_page_object_init');
# Init for the index (TOC), too.
$self->batch_mode_page_object_init($page, $module, $infile, $outfile, $depth)
if $self->can('batch_mode_page_object_init');
# Now get busy...
$self->makepath($outdir => \@namelets);
$progress and $progress->reach($self->{"__batch_conv_page_count"}, "Rendering $module");
if( $retval = $page->parse_from_file($infile, $outfile) ) {
++ $self->{"__batch_conv_page_count"} ;
$self->note_for_contents_file( \@namelets, $infile, $outfile );
} else {
$self->muse("Odd, parse_from_file(\"$infile\", \"$outfile\") returned false.");
}
$page->batch_mode_page_object_kill($self, $module, $infile, $outfile, $depth)
if $page->can('batch_mode_page_object_kill');
# The following isn't a typo. Note that it switches $self and $page.
$self->batch_mode_page_object_kill($page, $module, $infile, $outfile, $depth)
if $self->can('batch_mode_page_object_kill');
DEBUG > 4 and printf STDERR "%s %sb < $infile %s %sb\n",
$outfile, -s $outfile, $infile, -s $infile
;
undef($page);
return $retval;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub filespecsys { $_[0]{'_filespecsys'} || 'File::Spec' }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub note_for_contents_file {
my($self, $namelets, $infile, $outfile) = @_;
# I think the infile and outfile parts are never used. -- SMB
# But it's handy to have them around for debugging.
if( $self->contents_file ) {
my $c = $self->_contents();
push @$c,
[ join("::", @$namelets), $infile, $outfile, $namelets ]
# 0 1 2 3
;
DEBUG > 3 and print STDERR "Noting @$c[-1]\n";
}
return;
}
#_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
sub write_contents_file {
my($self, $outdir) = @_;
my $outfile = $self->_contents_filespec($outdir) || return;
$self->muse("Preparing list of modules for ToC");
my($toplevel, # maps toplevelbit => [all submodules]
$toplevel_form_freq, # ends up being 'foo' => 'Foo'
) = $self->_prep_contents_breakdown;
my $Contents = eval { $self->_wopen($outfile) };
( run in 3.444 seconds using v1.01-cache-2.11-cpan-d8267643d1d )