diff options
author | Yves Orton <demerphq@gmail.com> | 2023-03-19 18:58:11 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-03-22 02:53:47 +0800 |
commit | 03d84c69373359fcef54157b6459b1ce357daf09 (patch) | |
tree | cdc0ae3aa36e288809fbef769268dcd9baa3a7d5 /t | |
parent | 8312884dcdcc6d91617ebb943c385021054627d0 (diff) | |
download | perl-03d84c69373359fcef54157b6459b1ce357daf09.tar.gz |
t/TEST - rework poor mans getopt
Less cryptic and repetitive code.
Diffstat (limited to 't')
-rwxr-xr-x | t/TEST | 33 |
1 files changed, 24 insertions, 9 deletions
@@ -130,21 +130,36 @@ our $show_elapsed_time = $ENV{HARNESS_TIMER} || 0; # Cheesy version of Getopt::Std. We can't replace it with that, because we # can't rely on require working. { + my %opt_vars = ( + benchmark => \$::benchmark, + core => \$::core, + v => \$::verbose, + torture => \$::torture, + utf8 => \$::with_utf8, + utf16 => \$::with_utf16, + taintwarn => \$::taintwarn, + ); + my @argv = (); foreach my $idx (0..$#ARGV) { - push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/; - $::benchmark = 1 if $1 eq 'benchmark'; - $::core = 1 if $1 eq 'core'; - $::verbose = 1 if $1 eq 'v'; - $::torture = 1 if $1 eq 'torture'; - $::with_utf8 = 1 if $1 eq 'utf8'; - $::with_utf16 = 1 if $1 eq 'utf16'; - $::taintwarn = 1 if $1 eq 'taintwarn'; - if ($1 =~ /^deparse(,.+)?$/) { + my $opt; + if ($ARGV[$idx] =~ /^-?-(\S+)$/) { + $opt = $1; + } else { + push @argv, $ARGV[$idx]; + next; + } + if (my $ref = $opt_vars{$opt}) { + $$ref = 1; + } + elsif ($opt =~ /^deparse(,.+)?$/) { $::deparse = 1; $::deparse_opts = $1; _process_deparse_config(); } + else { + die "Unknown option '$opt'\n"; + } } @ARGV = @argv; } |