summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2021-07-12 00:28:11 +0000
committerJames E Keenan <jkeenan@cpan.org>2021-08-14 15:07:50 +0000
commitbc4a9d813672ab84362aa3371710f75c49a6f905 (patch)
treecf001ddb2dc725ff870d417c59fb99e610bb9339
parent9be343bf32d0921e5c792cbaa2b0038f43c6e463 (diff)
downloadperl-bc4a9d813672ab84362aa3371710f75c49a6f905.tar.gz
Pod-Html: Simplify the sub which processes options
Pod::Html::Util::parse_command_line() was doing too much. It should wrap around GetOptions(), call the usage() routine if needed, then return a hashref of options to its caller. Its caller -- Pod::Html::pod2html() -- should do the heavy lifting involved in processing the options and inserting the data into the globals hashref. Hence, we rename Pod::Html::Util::parse_command_line to Pod::Html::Util::process_command_line() and simplify its functionality. In lib/Pod/Html.pm we import process_command_line(), call it and pass its return value onto a new subroutine, process_options(), that populates $globals. Document Pod::Html::Util subroutines.
-rw-r--r--ext/Pod-Html/lib/Pod/Html.pm36
-rw-r--r--ext/Pod-Html/lib/Pod/Html/Util.pm94
2 files changed, 71 insertions, 59 deletions
diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm
index 01f4ec8ba9..a3232bc323 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,36 @@ sub init_globals {
return \%globals;
}
+sub process_options {
+ my ($globals, $opts) = @_;
+
+ @{$globals->{Podpath}} = split(":", $opts->{podpath}) if defined $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..26d323cb0c 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,67 +41,47 @@ 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.
+=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()>