Skip to content

Commit

Permalink
Introduce internal sub set_Title();
Browse files Browse the repository at this point in the history
Encapsulate more code within pod2html(). The return value is for
convenience.  It's the setting inside $globals that counts.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
  • Loading branch information
jkeenan committed Jul 6, 2021
1 parent 8bb6367 commit 072fb5a
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions ext/Pod-Html/lib/Pod/Html.pm
Expand Up @@ -326,24 +326,7 @@ sub pod2html {
}

my $podtree = parse_input_for_podtree($globals, $input);

unless(defined $globals->{Title}) {
if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" &&
$podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 &&
ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" &&
ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" &&
@{$podtree->[3]} >= 3 &&
!(grep { ref($_) ne "" }
@{$podtree->[3]}[2..$#{$podtree->[3]}]) &&
(@$podtree == 4 ||
(ref($podtree->[4]) eq "ARRAY" &&
$podtree->[4]->[0] eq "head1"))) {
$globals->{Title} = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]);
}
}

$globals->{Title} //= "";
$globals->{Title} = html_escape($globals->{Title});
$globals->{Title} = set_Title($globals, $podtree);

# set options for the HTML generator
my $parser = Pod::Simple::XHTML::LocalPodLinks->new();
Expand Down Expand Up @@ -452,6 +435,28 @@ sub parse_input_for_podtree {
return $podtree;
}
sub set_Title {
my ($globals, $podtree) = @_;
unless(defined $globals->{Title}) {
if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" &&
$podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 &&
ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" &&
ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" &&
@{$podtree->[3]} >= 3 &&
!(grep { ref($_) ne "" }
@{$podtree->[3]}[2..$#{$podtree->[3]}]) &&
(@$podtree == 4 ||
(ref($podtree->[4]) eq "ARRAY" &&
$podtree->[4]->[0] eq "head1"))) {
$globals->{Title} = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]);
}
}
$globals->{Title} //= "";
#$globals->{Title} = html_escape($globals->{Title});
return html_escape($globals->{Title});
}
sub get_cache {
my $globals = shift;
Expand Down

0 comments on commit 072fb5a

Please sign in to comment.