Skip to content

Commit

Permalink
Create sub write_file()
Browse files Browse the repository at this point in the history
We now start placing parts of sub pod2html() into separate subs so that
we reduce the length of pod2html(), making it more readable and
(ultimately) preparing for method calls.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
  • Loading branch information
jkeenan committed Jun 29, 2021
1 parent 1d61427 commit 0ed00b3
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions ext/Pod-Html/lib/Pod/Html.pm
Expand Up @@ -220,11 +220,11 @@ This program is distributed under the Artistic License.
sub feed_tree_to_parser {
my($parser, $tree) = @_;
if(ref($tree) eq "") {
$parser->_handle_text($tree);
$parser->_handle_text($tree);
} elsif(!($tree->[0] eq "X" && $parser->nix_X_codes)) {
$parser->_handle_element_start($tree->[0], $tree->[1]);
feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree];
$parser->_handle_element_end($tree->[0]);
$parser->_handle_element_start($tree->[0], $tree->[1]);
feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree];
$parser->_handle_element_end($tree->[0]);
}
}

Expand Down Expand Up @@ -437,19 +437,7 @@ HTMLFOOT
feed_tree_to_parser($parser, $podtree);
# Write output to file
$globals->{Htmlfile} = "-" unless $globals->{Htmlfile}; # stdout
my $fhout;
if($globals->{Htmlfile} and $globals->{Htmlfile} ne '-') {
open $fhout, ">", $globals->{Htmlfile}
or die "$0: cannot open $globals->{Htmlfile} file for output: $!\n";
} else {
open $fhout, ">-";
}
binmode $fhout, ":utf8";
print $fhout $output;
close $fhout or die "Failed to close $globals->{Htmlfile}: $!";
chmod 0644, $globals->{Htmlfile} unless $globals->{Htmlfile} eq '-';
write_file($globals, $output);
}
sub get_cache {
Expand Down Expand Up @@ -546,6 +534,22 @@ sub _save_page {
$Pages{$modname} = $dir.$file;
}

sub write_file {
my ($globals, $output) = @_;
$globals->{Htmlfile} = "-" unless $globals->{Htmlfile}; # stdout
my $FHOUT;
if($globals->{Htmlfile} and $globals->{Htmlfile} ne '-') {
open $FHOUT, ">", $globals->{Htmlfile}
or die "$0: cannot open $globals->{Htmlfile} file for output: $!\n";
} else {
open $FHOUT, ">-";
}
binmode $FHOUT, ":utf8";
print $FHOUT $output;
close $FHOUT or die "Failed to close $globals->{Htmlfile}: $!";
chmod 0644, $globals->{Htmlfile} unless $globals->{Htmlfile} eq '-';
}

package Pod::Simple::XHTML::LocalPodLinks;
use strict;
use warnings;
Expand Down

0 comments on commit 0ed00b3

Please sign in to comment.