From 25ea7eed7b9b430460290d7cc8c49e8a15dadb8e Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Thu, 18 Mar 2021 18:04:20 +0000 Subject: [PATCH] Replace _save_pages() with _transform() _save_pages() is a Pod::Simple::Search method which takes two specific arguments. From the point of view of making Pod-Html OO, it was problematic because (a) it used a variable ($Podroot) defined outside of its scope and (b) it assigned to a variable (%Pages) defined outside of its scope. It was therefore resistant to encapsulation. Experimentation showed that if we use the return value of Pod::Simple::Search::survey(), we could parse that hashref using what was the guts of _save_pages() and assign explicitly to %Pages. TODO: Move %Pages within the Pod::Html object. Handle $object properly. Signed-off-by: James E Keenan --- ext/Pod-Html/lib/Pod/Html.pm | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 9721e3480953..49d3d3e84d6a 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -238,16 +238,16 @@ sub pod2html { my $opts = process_command_line; $self->process_options($opts); - my $globals = $self->refine_globals(); + $self->refine_globals(); # load or generate/cache %Pages unless ($self->get_cache()) { # generate %Pages - %Pages = generate_cache($globals, \%Pages); + %Pages = $self->generate_cache(\%Pages); } my $input = $self->identify_input(); my $podtree = $self->parse_input_for_podtree($input); - $globals = $self->set_Title_from_podtree($podtree); + $self->set_Title_from_podtree($podtree); # set options for the HTML generator my $parser = Pod::Simple::XHTML::LocalPodLinks->new(); @@ -371,13 +371,15 @@ sub generate_cache { # limit search to those in @{$self->{Podpath}} # - verbose: report (via 'warn') what search is doing # - laborious: to allow '.' in dirnames (e.g., /usr/share/perl/5.14.1) - # - callback: used to remove Podroot and extension from each file # - recurse: go into subdirectories # - survey: search for POD files in PodPath my ($name2path, $path2name) = Pod::Simple::Search->new->inc(0)->verbose($self->{Verbose})->laborious(1) - ->callback(\&_save_page)->recurse($self->{Recurse})->survey(@{$self->{Podpath}}); - #print STDERR Data::Dumper::Dumper($name2path, $path2name) if ($self->{Verbose}); + ->recurse($self->{Recurse})->survey(@{$self->{Podpath}}); + # remove Podroot and extension from each file + for my $k (keys %{$name2path}) { + $Pages{$k} = _transform($self, $name2path->{$k}); + } chdir($pwd) || die "$0: error changing to directory $pwd: $!\n"; @@ -403,23 +405,18 @@ sub generate_cache { return %{$Pagesref}; } -# -# store POD files in %Pages -# -sub _save_page { - my ($modspec, $modname) = @_; - - # Remove Podroot from path - $modspec = $Podroot eq File::Spec->curdir - ? File::Spec->abs2rel($modspec) - : File::Spec->abs2rel($modspec, - File::Spec->canonpath($Podroot)); +sub _transform { + my ($self, $v) = @_; + $v = $self->{Podroot} eq File::Spec->curdir + ? File::Spec->abs2rel($v) + : File::Spec->abs2rel($v, + File::Spec->canonpath($self->{Podroot})); # Convert path to unix style path - $modspec = unixify($modspec); + $v = unixify($v); - my ($file, $dir) = fileparse($modspec, qr/\.[^.]*/); # strip .ext - $Pages{$modname} = $dir.$file; + my ($file, $dir) = fileparse($v, qr/\.[^.]*/); # strip .ext + return $dir.$file; } sub get_cache { @@ -545,7 +542,7 @@ sub set_Title_from_podtree { } $self->{Title} //= ""; - return { %{$self} }; + return $self; } sub refine_parser { @@ -627,6 +624,14 @@ sub write_file { chmod 0644, $self->{Htmlfile} unless $self->{Htmlfile} eq '-'; } +#sub compare { +# my ($ha, $hb) = @_; +# local $Data::Dumper::Terse = 1; +# local $Data::Dumper::Indent = 0; +# local $Data::Dumper::Sortkeys = 1; +# return (Dumper($ha) eq Dumper($hb)) ? 1 : 0; +#} + package Pod::Simple::XHTML::LocalPodLinks; use strict; use warnings;