summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2021-08-14 15:08:04 +0000
committerJames E Keenan <jkeenan@cpan.org>2021-08-14 15:08:04 +0000
commitca5ef5cf0c031c02848b858299784105a60e33e8 (patch)
tree207664d3ea4ed7d632694f5562276a0f2e24d1a2
parent9be343bf32d0921e5c792cbaa2b0038f43c6e463 (diff)
parent4b79ccc8bc29ed54bb9a9e62d7ecc0162dba10f5 (diff)
downloadperl-ca5ef5cf0c031c02848b858299784105a60e33e8.tar.gz
Merge branch 'pod-html-refactoring-4-of-5' into blead
-rw-r--r--ext/Pod-Html/lib/Pod/Html.pm38
-rw-r--r--ext/Pod-Html/lib/Pod/Html/Util.pm98
2 files changed, 76 insertions, 60 deletions
diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm
index 01f4ec8ba9..708f64625f 100644
--- a/ext/Pod-Html/lib/Pod/Html.pm
+++ b/ext/Pod-Html/lib/Pod/Html.pm
@@ -16,7 +16,7 @@ use Pod::Simple::Search;
use Pod::Simple::SimpleTree ();
use Pod::Html::Util qw(
html_escape
- parse_command_line
+ process_command_line
trim_leading_whitespace
unixify
usage
@@ -250,7 +250,9 @@ sub pod2html {
local $_;
my $globals = init_globals();
- $globals = parse_command_line($globals);
+ my $opts = process_command_line;
+ $globals = process_options($globals, $opts);
+
$globals = refine_globals($globals);
# load or generate/cache %Pages
@@ -319,6 +321,38 @@ sub init_globals {
return \%globals;
}
+sub process_options {
+ my ($globals, $opts) = @_;
+
+ $globals->{Podpath} = (defined $opts->{podpath})
+ ? [ split(":", $opts->{podpath}) ]
+ : [];
+
+ $globals->{Backlink} = $opts->{backlink} if defined $opts->{backlink};
+ $globals->{Cachedir} = unixify($opts->{cachedir}) if defined $opts->{cachedir};
+ $globals->{Css} = $opts->{css} if defined $opts->{css};
+ $globals->{Header} = $opts->{header} if defined $opts->{header};
+ $globals->{Htmldir} = unixify($opts->{htmldir}) if defined $opts->{htmldir};
+ $globals->{Htmlroot} = unixify($opts->{htmlroot}) if defined $opts->{htmlroot};
+ $globals->{Doindex} = $opts->{index} if defined $opts->{index};
+ $globals->{Podfile} = unixify($opts->{infile}) if defined $opts->{infile};
+ $globals->{Htmlfile} = unixify($opts->{outfile}) if defined $opts->{outfile};
+ $globals->{Poderrors} = $opts->{poderrors} if defined $opts->{poderrors};
+ $globals->{Podroot} = unixify($opts->{podroot}) if defined $opts->{podroot};
+ $globals->{Quiet} = $opts->{quiet} if defined $opts->{quiet};
+ $globals->{Recurse} = $opts->{recurse} if defined $opts->{recurse};
+ $globals->{Title} = $opts->{title} if defined $opts->{title};
+ $globals->{Verbose} = $opts->{verbose} if defined $opts->{verbose};
+
+ warn "Flushing directory caches\n"
+ if $opts->{verbose} && defined $opts->{flush};
+ $globals->{Dircache} = "$globals->{Cachedir}/pod2htmd.tmp";
+ if (defined $opts->{flush}) {
+ 1 while unlink($globals->{Dircache});
+ }
+ return $globals;
+}
+
sub refine_globals {
my $globals = shift;
require Data::Dumper if $globals->{verbose};
diff --git a/ext/Pod-Html/lib/Pod/Html/Util.pm b/ext/Pod-Html/lib/Pod/Html/Util.pm
index 9f33bff91e..bf95703a78 100644
--- a/ext/Pod-Html/lib/Pod/Html/Util.pm
+++ b/ext/Pod-Html/lib/Pod/Html/Util.pm
@@ -9,7 +9,7 @@ our @EXPORT_OK = qw(
anchorify
html_escape
htmlify
- parse_command_line
+ process_command_line
relativize_url
trim_leading_whitespace
unixify
@@ -41,72 +41,54 @@ just described.
=cut
-# parse_command_line will be moved back to lib/Pod/Html.pm in a subsequent
-# p.r. and will be documented then and there
+=head2 C<process_command_line()>
-sub parse_command_line {
- my $globals = shift;
- my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,
- $opt_help,$opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,
- $opt_outfile,$opt_poderrors,$opt_podpath,$opt_podroot,
- $opt_quiet,$opt_recurse,$opt_title,$opt_verbose);
+Process command-line switches (options). Returns a reference to a hash. Will
+provide usage message if C<--help> switch is present or if parameters are
+invalid.
+Calling this subroutine may modify C<@ARGV>.
+
+=cut
+
+sub process_command_line {
+ my %opts = map { $_ => undef } (qw|
+ backlink cachedir css flush
+ header help htmldir htmlroot
+ index infile outfile poderrors
+ podpath podroot quiet recurse
+ title verbose
+ |);
unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
- my $result = GetOptions(
- 'backlink!' => \$opt_backlink,
- 'cachedir=s' => \$opt_cachedir,
- 'css=s' => \$opt_css,
- 'flush' => \$opt_flush,
- 'help' => \$opt_help,
- 'header!' => \$opt_header,
- 'htmldir=s' => \$opt_htmldir,
- 'htmlroot=s' => \$opt_htmlroot,
- 'index!' => \$opt_index,
- 'infile=s' => \$opt_infile,
- 'outfile=s' => \$opt_outfile,
- 'poderrors!' => \$opt_poderrors,
- 'podpath=s' => \$opt_podpath,
- 'podroot=s' => \$opt_podroot,
- 'quiet!' => \$opt_quiet,
- 'recurse!' => \$opt_recurse,
- 'title=s' => \$opt_title,
- 'verbose!' => \$opt_verbose,
+ my $result = GetOptions(\%opts,
+ 'backlink!',
+ 'cachedir=s',
+ 'css=s',
+ 'flush',
+ 'help',
+ 'header!',
+ 'htmldir=s',
+ 'htmlroot=s',
+ 'index!',
+ 'infile=s',
+ 'outfile=s',
+ 'poderrors!',
+ 'podpath=s',
+ 'podroot=s',
+ 'quiet!',
+ 'recurse!',
+ 'title=s',
+ 'verbose!',
);
usage("-", "invalid parameters") if not $result;
-
- usage("-") if defined $opt_help; # see if the user asked for help
- $opt_help = ""; # just to make -w shut-up.
-
- @{$globals->{Podpath}} = split(":", $opt_podpath) if defined $opt_podpath;
-
- $globals->{Backlink} = $opt_backlink if defined $opt_backlink;
- $globals->{Cachedir} = unixify($opt_cachedir) if defined $opt_cachedir;
- $globals->{Css} = $opt_css if defined $opt_css;
- $globals->{Header} = $opt_header if defined $opt_header;
- $globals->{Htmldir} = unixify($opt_htmldir) if defined $opt_htmldir;
- $globals->{Htmlroot} = unixify($opt_htmlroot) if defined $opt_htmlroot;
- $globals->{Doindex} = $opt_index if defined $opt_index;
- $globals->{Podfile} = unixify($opt_infile) if defined $opt_infile;
- $globals->{Htmlfile} = unixify($opt_outfile) if defined $opt_outfile;
- $globals->{Poderrors} = $opt_poderrors if defined $opt_poderrors;
- $globals->{Podroot} = unixify($opt_podroot) if defined $opt_podroot;
- $globals->{Quiet} = $opt_quiet if defined $opt_quiet;
- $globals->{Recurse} = $opt_recurse if defined $opt_recurse;
- $globals->{Title} = $opt_title if defined $opt_title;
- $globals->{Verbose} = $opt_verbose if defined $opt_verbose;
-
- warn "Flushing directory caches\n"
- if $opt_verbose && defined $opt_flush;
- $globals->{Dircache} = "$globals->{Cachedir}/pod2htmd.tmp";
- if (defined $opt_flush) {
- 1 while unlink($globals->{Dircache});
- }
- return $globals;
+ usage("-") if defined $opts{help}; # see if the user asked for help
+ $opts{help} = ""; # just to make -w shut-up.
+ return \%opts;
}
=head2 C<usage()>
-Display customary Pod::Html usage information.
+Display customary Pod::Html usage information on STDERR.
=cut