From c0aab9dd7f524697b044451bddc72fc8edb3b0e0 Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Mon, 10 Nov 2025 14:25:16 -0500 Subject: [PATCH 1/2] Tidy lib/Getopt/Std.pm Uncuddle elsif and else; standardize leading whitespace; trim trailing whitespace. Increment $VERSION. --- lib/Getopt/Std.pm | 295 +++++++++++++++++++++++----------------------- 1 file changed, 149 insertions(+), 146 deletions(-) diff --git a/lib/Getopt/Std.pm b/lib/Getopt/Std.pm index 855d3c1c129b..3560f7baafa2 100644 --- a/lib/Getopt/Std.pm +++ b/lib/Getopt/Std.pm @@ -14,7 +14,7 @@ Getopt::Std - Process single-character switches with switch clustering use Getopt::Std; getopts('oif:'); # -o & -i are boolean flags, -f takes an argument - # Sets $opt_* global variables as a side effect + # Sets $opt_* global variables as a side effect getopts('oif:', \my %opts); # Options as above, values in %opts getopt('oDI'); # -o, -D & -I take arguments # Sets $opt_* global variables as a side effect @@ -84,7 +84,7 @@ and C with the switches string as an argument. our @ISA = qw(Exporter); our @EXPORT = qw(getopt getopts); -our $VERSION = '1.14'; +our $VERSION = '1.15'; # uncomment the next line to disable 1.03-backward compatibility paranoia # $STANDARD_HELP_VERSION = 1; @@ -95,7 +95,7 @@ our $VERSION = '1.14'; # whether there is a space between the switch and the argument. # Usage: -# getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect. +# getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect. sub getopt (;$$) { my ($argumentative, $hash) = @_; @@ -105,56 +105,56 @@ sub getopt (;$$) { local @EXPORT; while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) { - ($first, $rest) = ($1, $2); - if (/^--$/) { # early exit if -- - shift @ARGV; - last; - } - if (index($argumentative, $first) >= 0) { - if ($rest ne '') { - shift(@ARGV); - } - else { - shift(@ARGV); - $rest = shift(@ARGV); - } - if (ref $hash) { - $$hash{$first} = $rest; - } - else { - no strict 'refs'; - ${"opt_$first"} = $rest; - push( @EXPORT, "\$opt_$first" ); - } - } - else { - if (ref $hash) { - $$hash{$first} = 1; - } - else { - no strict 'refs'; - ${"opt_$first"} = 1; - push( @EXPORT, "\$opt_$first" ); - } - if ($rest ne '') { - $ARGV[0] = "-$rest"; - } - else { - shift(@ARGV); - } - } + ($first, $rest) = ($1, $2); + if (/^--$/) { # early exit if -- + shift @ARGV; + last; + } + if (index($argumentative, $first) >= 0) { + if ($rest ne '') { + shift(@ARGV); + } + else { + shift(@ARGV); + $rest = shift(@ARGV); + } + if (ref $hash) { + $$hash{$first} = $rest; + } + else { + no strict 'refs'; + ${"opt_$first"} = $rest; + push( @EXPORT, "\$opt_$first" ); + } + } + else { + if (ref $hash) { + $$hash{$first} = 1; + } + else { + no strict 'refs'; + ${"opt_$first"} = 1; + push( @EXPORT, "\$opt_$first" ); + } + if ($rest ne '') { + $ARGV[0] = "-$rest"; + } + else { + shift(@ARGV); + } + } } - unless (ref $hash) { - local $Exporter::ExportLevel = 1; - Getopt::Std->import; + unless (ref $hash) { + local $Exporter::ExportLevel = 1; + Getopt::Std->import; } } our ($OUTPUT_HELP_VERSION, $STANDARD_HELP_VERSION); sub output_h () { - return $OUTPUT_HELP_VERSION if defined $OUTPUT_HELP_VERSION; - return \*STDOUT if $STANDARD_HELP_VERSION; - return \*STDERR; + return $OUTPUT_HELP_VERSION if defined $OUTPUT_HELP_VERSION; + return \*STDOUT if $STANDARD_HELP_VERSION; + return \*STDERR; } sub try_exit () { @@ -170,15 +170,16 @@ sub version_mess ($;$) { my $args = shift; my $h = output_h; if (@_ and defined &main::VERSION_MESSAGE) { - main::VERSION_MESSAGE($h, __PACKAGE__, $VERSION, $args); - } else { - my $v = $main::VERSION; - $v = '[unknown]' unless defined $v; - my $myv = $VERSION; - $myv .= ' [paranoid]' unless $STANDARD_HELP_VERSION; - my $perlv = $]; - $perlv = sprintf "%vd", $^V if $] >= 5.006; - print $h <= 5.006; + print $h <) { - $has_pod = 1, last if /^=(pod|head1)/; - } - } - print $h <) { + $has_pod = 1, last if /^=(pod|head1)/; + } + } + print $h <= 0) { - if (defined($args[$pos+1]) and ($args[$pos+1] eq ':')) { - shift(@ARGV); - if ($rest eq '') { - ++$errs unless @ARGV; - $rest = shift(@ARGV); - } - if (ref $hash) { - $$hash{$first} = $rest; - } - else { - no strict 'refs'; - ${"opt_$first"} = $rest; - push( @EXPORT, "\$opt_$first" ); - } - } - else { - if (ref $hash) { - $$hash{$first} = 1; - } - else { - no strict 'refs'; - ${"opt_$first"} = 1; - push( @EXPORT, "\$opt_$first" ); - } - if ($rest eq '') { - shift(@ARGV); - } - else { - $ARGV[0] = "-$rest"; - } - } - } - else { - if ($first eq '-' and $rest eq 'help') { - version_mess($argumentative, 'main'); - help_mess($argumentative, 'main'); - try_exit(); - shift(@ARGV); - next; - } elsif ($first eq '-' and $rest eq 'version') { - version_mess($argumentative, 'main'); - try_exit(); - shift(@ARGV); - next; - } - warn "Unknown option: $first\n"; - ++$errs; - if ($rest ne '') { - $ARGV[0] = "-$rest"; - } - else { - shift(@ARGV); - } - } + ($first, $rest) = ($1, $2); + if (/^--$/) { # early exit if -- + shift @ARGV; + last; + } + my $pos = index($argumentative, $first); + if ($pos >= 0) { + if (defined($args[$pos+1]) and ($args[$pos+1] eq ':')) { + shift(@ARGV); + if ($rest eq '') { + ++$errs unless @ARGV; + $rest = shift(@ARGV); + } + if (ref $hash) { + $$hash{$first} = $rest; + } + else { + no strict 'refs'; + ${"opt_$first"} = $rest; + push( @EXPORT, "\$opt_$first" ); + } + } + else { + if (ref $hash) { + $$hash{$first} = 1; + } + else { + no strict 'refs'; + ${"opt_$first"} = 1; + push( @EXPORT, "\$opt_$first" ); + } + if ($rest eq '') { + shift(@ARGV); + } + else { + $ARGV[0] = "-$rest"; + } + } + } + else { + if ($first eq '-' and $rest eq 'help') { + version_mess($argumentative, 'main'); + help_mess($argumentative, 'main'); + try_exit(); + shift(@ARGV); + next; + } + elsif ($first eq '-' and $rest eq 'version') { + version_mess($argumentative, 'main'); + try_exit(); + shift(@ARGV); + next; + } + warn "Unknown option: $first\n"; + ++$errs; + if ($rest ne '') { + $ARGV[0] = "-$rest"; + } + else { + shift(@ARGV); + } + } } - unless (ref $hash) { - local $Exporter::ExportLevel = 1; - Getopt::Std->import; + unless (ref $hash) { + local $Exporter::ExportLevel = 1; + Getopt::Std->import; } $errs == 0; } From 39283d2fd170166c77e130fca26627dae4ab74b5 Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Mon, 10 Nov 2025 14:29:28 -0500 Subject: [PATCH 2/2] Tidy lib/Getopt/Std.t Replace internal hard-tabs used for alignment of test descriptions. --- lib/Getopt/Std.t | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Getopt/Std.t b/lib/Getopt/Std.t index 325226a5ed0e..1660f9554be4 100644 --- a/lib/Getopt/Std.t +++ b/lib/Getopt/Std.t @@ -17,41 +17,41 @@ our ($warning, $opt_f, $opt_i, $opt_o, $opt_x, $opt_y, %opt); @ARGV = qw(-xo -f foo -y file); getopt('f'); -is( "@ARGV", 'file', 'options removed from @ARGV (1)' ); +is( "@ARGV", 'file', 'options removed from @ARGV (1)' ); ok( $opt_x && $opt_o && $opt_y, 'options -x, -o and -y set' ); -is( $opt_f, 'foo', q/option -f is 'foo'/ ); +is( $opt_f, 'foo', q/option -f is 'foo'/ ); @ARGV = qw(-hij k -- -l m -n); getopt 'il', \%opt; -is( "@ARGV", 'k -- -l m -n', 'options removed from @ARGV (2)' ); -ok( $opt{h} && $opt{i} eq 'j', 'option -h and -i correctly set' ); -ok( !defined $opt{l}, 'option -l not set' ); -ok( !defined $opt_i, '$opt_i still undefined' ); +is( "@ARGV", 'k -- -l m -n', 'options removed from @ARGV (2)' ); +ok( $opt{h} && $opt{i} eq 'j', 'option -h and -i correctly set' ); +ok( !defined $opt{l}, 'option -l not set' ); +ok( !defined $opt_i, '$opt_i still undefined' ); # Then we try the getopts $opt_o = $opt_i = $opt_f = undef; @ARGV = qw(-foi -i file); -ok( getopts('oif:'), 'getopts succeeded (1)' ); -is( "@ARGV", 'file', 'options removed from @ARGV (3)' ); -ok( $opt_i && $opt_f eq 'oi', 'options -i and -f correctly set' ); -ok( !defined $opt_o, 'option -o not set' ); +ok( getopts('oif:'), 'getopts succeeded (1)' ); +is( "@ARGV", 'file', 'options removed from @ARGV (3)' ); +ok( $opt_i && $opt_f eq 'oi', 'options -i and -f correctly set' ); +ok( !defined $opt_o, 'option -o not set' ); %opt = (); $opt_i = undef; @ARGV = qw(-hij -k -- -l m); -ok( getopts('hi:kl', \%opt), 'getopts succeeded (2)' ); -is( "@ARGV", '-l m', 'options removed from @ARGV (4)' ); -ok( $opt{h} && $opt{k}, 'options -h and -k set' ); -is( $opt{i}, 'j', q/option -i is 'j'/ ); -ok( !defined $opt_i, '$opt_i still undefined' ); +ok( getopts('hi:kl', \%opt), 'getopts succeeded (2)' ); +is( "@ARGV", '-l m', 'options removed from @ARGV (4)' ); +ok( $opt{h} && $opt{k}, 'options -h and -k set' ); +is( $opt{i}, 'j', q/option -i is 'j'/ ); +ok( !defined $opt_i, '$opt_i still undefined' ); # Try illegal options, but avoid printing of the error message $SIG{__WARN__} = sub { $warning = $_[0] }; @ARGV = qw(-h help); -ok( !getopts("xf:y"), 'getopts fails for an illegal option' ); +ok( !getopts("xf:y"), 'getopts fails for an illegal option' ); ok( $warning eq "Unknown option: h\n", 'user warned' ); # Tests for RT #41359