Skip to content

Commit

Permalink
Create internal sub parse_input_for_podtree()
Browse files Browse the repository at this point in the history
This clears up a bit of semantic confusion.  We were using one lexically
scoped variable -- my $parser -- to hold two different objects: one for
parsing input, one for writing output.  We can encapsulate the working
of the input parser to make the code more readable.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
  • Loading branch information
jkeenan committed Jun 29, 2021
1 parent a2556d0 commit 85eb0f1
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions ext/Pod-Html/lib/Pod/Html.pm
Expand Up @@ -343,17 +343,7 @@ sub pod2html {
$input = *ARGV;
}

# set options for input parser
my $parser = Pod::Simple::SimpleTree->new;
# Normalize whitespace indenting
$parser->strip_verbatim_indent(\&trim_leading_whitespace);

$parser->codes_in_verbatim(0);
$parser->accept_targets(qw(html HTML));
$parser->no_errata_section(!$globals->{Poderrors}); # note the inverse

warn "Converting input file $globals->{Podfile}\n" if $globals->{Verbose};
my $podtree = $parser->parse_file($input)->root;
my $podtree = parse_input_for_podtree($globals, $input);

unless(defined $globals->{Title}) {
if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" &&
Expand All @@ -374,7 +364,8 @@ sub pod2html {
$globals->{Title} = html_escape($globals->{Title});

# set options for the HTML generator
$parser = Pod::Simple::XHTML::LocalPodLinks->new();
my $parser = Pod::Simple::XHTML::LocalPodLinks->new();
my $output;
$parser->codes_in_verbatim(0);
$parser->anchor_items(1); # the old Pod::Html always did
$parser->backlink($globals->{Backlink}); # linkify =head1 directives
Expand All @@ -383,7 +374,7 @@ sub pod2html {
$parser->htmlfileurl($globals->{Htmlfileurl});
$parser->htmlroot($globals->{Htmlroot});
$parser->index($globals->{Doindex});
$parser->output_string(\my $output); # written to file later
$parser->output_string(\$output); # written to file later
$parser->pages(\%Pages);
$parser->quiet($globals->{Quiet});
$parser->verbose($globals->{Verbose});
Expand Down Expand Up @@ -439,6 +430,22 @@ HTMLFOOT
write_file($globals, $output);
}
sub parse_input_for_podtree {
my ($globals, $input) = @_;
# set options for input parser
my $input_parser = Pod::Simple::SimpleTree->new;
# Normalize whitespace indenting
$input_parser->strip_verbatim_indent(\&trim_leading_whitespace);
$input_parser->codes_in_verbatim(0);
$input_parser->accept_targets(qw(html HTML));
$input_parser->no_errata_section(!$globals->{Poderrors}); # note the inverse
warn "Converting input file $globals->{Podfile}\n" if $globals->{Verbose};
my $podtree = $input_parser->parse_file($input)->root;
return $podtree;
}
sub get_cache {
my $globals = shift;
Expand Down

0 comments on commit 85eb0f1

Please sign in to comment.