PerlBench
view release on metacpan or search on metacpan
benchmarks/app/MyPodHtml.pm view on Meta::CPAN
my( $dataref ) = @_;
for my $i ( 0..$#{$dataref} ) {
${$dataref}[$i] =~ s/\s+\Z//;
# have a look for all-space lines
if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
splice( @$dataref, $i, 1, @chunks );
}
}
}
sub pod2html {
local(@ARGV) = @_;
local($/);
local $_;
init_globals();
$Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
# cache of %Pages and %Items from last time we ran pod2html
#undef $opt_help if defined $opt_help;
# parse the command-line parameters
parse_command_line();
# escape the backlink argument (same goes for title but is done later...)
$Backlink = html_escape($Backlink) if defined $Backlink;
# set some variables to their default values if necessary
local *POD;
unless (@ARGV && $ARGV[0]) {
$Podfile = "-" unless $Podfile; # stdin
open(POD, "<$Podfile")
|| die "$0: cannot open $Podfile file for input: $!\n";
} else {
$Podfile = $ARGV[0]; # XXX: might be more filenames
*POD = *ARGV;
}
$Htmlfile = "-" unless $Htmlfile; # stdout
$Htmlroot = "" if $Htmlroot eq "/"; # so we don't get a //
$Htmldir =~ s#/\z## ; # so we don't get a //
if ( $Htmlroot eq ''
&& defined( $Htmldir )
&& $Htmldir ne ''
&& substr( $Htmlfile, 0, length( $Htmldir ) ) eq $Htmldir
)
{
# Set the 'base' url for this file, so that we can use it
# as the location from which to calculate relative links
# to other files. If this is '', then absolute links will
# be used throughout.
$Htmlfileurl= "$Htmldir/" . substr( $Htmlfile, length( $Htmldir ) + 1);
}
# read the pod a paragraph at a time
warn "Scanning for sections in input file(s)\n" if $Verbose;
$/ = "";
my @poddata = <POD>;
close(POD);
# be eol agnostic
for (@poddata) {
if (/\r/) {
if (/\r\n/) {
@poddata = map { s/\r\n/\n/g;
/\n\n/ ?
map { "$_\n\n" } split /\n\n/ :
$_ } @poddata;
} else {
@poddata = map { s/\r/\n/g;
/\n\n/ ?
map { "$_\n\n" } split /\n\n/ :
$_ } @poddata;
}
last;
}
}
clean_data( \@poddata );
# scan the pod for =head[1-6] directives and build an index
my $index = scan_headings(\%Sections, @poddata);
unless($index) {
warn "No headings in $Podfile\n" if $Verbose;
}
# open the output file
open(HTML, ">$Htmlfile")
|| die "$0: cannot open $Htmlfile file for output: $!\n";
# put a title in the HTML file if one wasn't specified
if ($Title eq '') {
TITLE_SEARCH: {
for (my $i = 0; $i < @poddata; $i++) {
if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
for my $para ( @poddata[$i, $i+1] ) {
last TITLE_SEARCH
if ($Title) = $para =~ /(\S+\s+-+.*\S)/s;
}
}
}
}
}
if (!$Title and $Podfile =~ /\.pod\z/) {
# probably a split pod so take first =head[12] as title
for (my $i = 0; $i < @poddata; $i++) {
last if ($Title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
}
warn "adopted '$Title' as title for $Podfile\n"
if $Verbose and $Title;
}
if ($Title) {
$Title =~ s/\s*\(.*\)//;
} else {
warn "$0: no title for $Podfile.\n" unless $Quiet;
( run in 0.661 second using v1.01-cache-2.11-cpan-364913b4093 )