summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2021-03-18 18:04:20 +0000
committerJames E Keenan <jkeenan@cpan.org>2021-08-23 01:47:47 +0000
commit06dda0b0ccbe2aec353c1a8c1bd1ea3adb085b4a (patch)
tree43d350c1fe1e2a915a7fda24b0c182577790e1c3 /ext
parentb9cd5823f4b35b7d870d17a180afa9d91cc3f3dd (diff)
downloadperl-06dda0b0ccbe2aec353c1a8c1bd1ea3adb085b4a.tar.gz
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 <jkeenan@cpan.org> Remove merge conflict marks, commented-out code, as noted by rjbs in https://github.com/Perl/perl5/pull/19050#discussion_r693559914.
Diffstat (limited to 'ext')
-rw-r--r--ext/Pod-Html/lib/Pod/Html.pm40
1 files changed, 18 insertions, 22 deletions
diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm
index f7e6ddbf14..6a4410e500 100644
--- a/ext/Pod-Html/lib/Pod/Html.pm
+++ b/ext/Pod-Html/lib/Pod/Html.pm
@@ -260,16 +260,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();
@@ -393,13 +393,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";
@@ -425,23 +427,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 {
@@ -567,7 +564,7 @@ sub set_Title_from_podtree {
}
$self->{Title} //= "";
- return { %{$self} };
+ return $self;
}
sub refine_parser {
@@ -649,7 +646,6 @@ sub write_file {
chmod 0644, $self->{Htmlfile} unless $self->{Htmlfile} eq '-';
}
-
package Pod::Simple::XHTML::LocalPodLinks;
use strict;
use warnings;