summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2021-03-16 21:46:19 +0000
committerJames E Keenan <jkeenan@cpan.org>2021-07-06 01:08:03 +0000
commitc97f73fe8db20adb57725eac1957667c9036399b (patch)
tree37bd867e7f9919d3ed2897095183b2d38a524cb5
parent5cae71e5baf19f8c46e55ab0222d90a874b66726 (diff)
downloadperl-c97f73fe8db20adb57725eac1957667c9036399b.tar.gz
Create internal sub parse_input_for_podtree()
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>
-rw-r--r--ext/Pod-Html/lib/Pod/Html.pm33
1 files changed, 20 insertions, 13 deletions
diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm
index d2b2d8c051..118812bf76 100644
--- a/ext/Pod-Html/lib/Pod/Html.pm
+++ b/ext/Pod-Html/lib/Pod/Html.pm
@@ -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" &&
@@ -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
@@ -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});
@@ -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;