Skip to content

Commit

Permalink
Introduce $self->{Pages}
Browse files Browse the repository at this point in the history
htmldir3.t: 3rd test unit is now expected to fail.  So now the test file
demonstrates that the unit fails whether it's placed before the second
unit or after.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
  • Loading branch information
jkeenan committed Aug 20, 2021
1 parent 030e2cc commit 64d3944
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions ext/Pod-Html/lib/Pod/Html.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ This program is distributed under the Artistic License.

my $Podroot;

my %Pages = (); # associative array used to find the location
#my %Pages = (); # associative array used to find the location
# of pages referenced by L<> links.

sub new {
Expand All @@ -265,7 +265,8 @@ sub pod2html {
# load or generate/cache %Pages
unless ($self->get_cache()) {
# generate %Pages
%Pages = $self->generate_cache(\%Pages);
#%Pages = $self->generate_cache(\%Pages);
$self->generate_cache($self->{Pages});
}
my $input = $self->identify_input();
my $podtree = $self->parse_input_for_podtree($input);
Expand All @@ -282,7 +283,8 @@ sub pod2html {
$parser->htmlroot($self->{Htmlroot});
$parser->index($self->{Doindex});
$parser->output_string(\$self->{output}); # written to file later
$parser->pages(\%Pages);
#$parser->pages(\%Pages);
$parser->pages($self->{Pages});
$parser->quiet($self->{Quiet});
$parser->verbose($self->{Verbose});

Expand Down Expand Up @@ -323,6 +325,7 @@ sub init_globals {
$self->{Header} = 0; # produce block header/footer
$self->{Title} = undef; # title to give the pod(s)
$self->{Saved_Cache_Key} = '';
$self->{Pages} = {};
return $self;
}

Expand Down Expand Up @@ -382,7 +385,8 @@ sub refine_globals {
}

sub generate_cache {
my ($self, $Pagesref) = @_;
#my ($self, $Pagesref) = @_;
my $self = shift;
my $pwd = getcwd();
chdir($self->{Podroot}) ||
die "$0: error changing to directory $self->{Podroot}: $!\n";
Expand All @@ -399,7 +403,7 @@ sub generate_cache {
->recurse($self->{Recurse})->survey(@{$self->{Podpath}});
# remove Podroot and extension from each file
for my $k (keys %{$name2path}) {
$Pages{$k} = _transform($self, $name2path->{$k});
$self->{Pages}{$k} = _transform($self, $name2path->{$k});
}

chdir($pwd) || die "$0: error changing to directory $pwd: $!\n";
Expand All @@ -411,19 +415,19 @@ sub generate_cache {

print $cache join(":", @{$self->{Podpath}}) . "\n$self->{Podroot}\n";
my $_updirs_only = ($self->{Podroot} =~ /\.\./) && !($self->{Podroot} =~ /[^\.\\\/]/);
foreach my $key (keys %{$Pagesref}) {
foreach my $key (keys %{$self->{Pages}}) {
if($_updirs_only) {
my $_dirlevel = $self->{Podroot};
while($_dirlevel =~ /\.\./) {
$_dirlevel =~ s/\.\.//;
# Assume $Pagesref->{$key} has '/' separators (html dir separators).
$Pagesref->{$key} =~ s/^[\w\s\-\.]+\///;
$self->{Pages}->{$key} =~ s/^[\w\s\-\.]+\///;
}
}
print $cache "$key $Pagesref->{$key}\n";
print $cache "$key $self->{Pages}->{$key}\n";
}
close $cache or die "error closing $self->{Dircache}: $!";
return %{$Pagesref};
#return %{$Pagesref};
}

sub _transform {
Expand Down Expand Up @@ -506,7 +510,7 @@ sub load_cache {
warn "loading directory cache\n" if $self->{Verbose};
while (<$cachefh>) {
/(.*?) (.*)$/;
$Pages{$1} = $2;
$self->{Pages}->{$1} = $2;
}

close($cachefh);
Expand Down
3 changes: 2 additions & 1 deletion ext/Pod-Html/t/htmldir3.t
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ xconvert($args);

$args = {
podstub => "htmldir3",
description => "test --htmldir and --htmlroot 3b",
description => "test --htmldir and --htmlroot 3b: as expected pod file not yet locatable either under podroot or in cache: GH 12271",
expect => $expect_raw,
expect_fail => 1,
p2h => {
podpath => catdir($relcwd, 't'),
podroot => catpath($v, '/', ''),
Expand Down

0 comments on commit 64d3944

Please sign in to comment.