| 1 | # -*- Mode: perl -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | package Getargs::Long; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | $VERSION = sprintf "%d.%02d%02d", q/1.10.7/ =~ /(\d+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | die "This module is known to exercise a bug in 5.6.0. Please upgrade your perl.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | if $] eq '5.006'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Log::Agent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use vars qw(@EXPORT); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | @EXPORT = qw(getargs cgetargs xgetargs cxgetargs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # %ignore | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Cache whether argument names are to be handled case-insensitively or not, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # on a package basis. Default is case-sensitive processing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my %ignore = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # ->import | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # Trap Exporter's one to handle 'ignorecase' here (or lack thereof). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Then use ->export_to_level() to tell Exporter to continue the export | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # as if its import method had been called directly via inheritance. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | my $module = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | my @syms = grep($_ ne 'ignorecase', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | my $callpkg = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | if (@syms == @_) { # There was no "ignorecase" seen | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | delete $ignore{$callpkg}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | logdbg 'info', "will process arguments case-sensitively in $callpkg"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | $ignore{$callpkg} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | logdbg 'info', "will process arguments case-insensitively in $callpkg"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | Getargs::Long->export_to_level(1, $module, @syms); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # %subcache | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Cache validation routine, indexed by "package::routine". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | my %subcache = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # getargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # Parse arguments for subroutine, and validate them if typechecking requested. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Optional arguments with no default return undef. Mandatory arguments cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # be undefined. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | sub getargs (\@@) { _getargs(scalar(caller), 0, "", @_) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getargs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # cgetargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Same as getargs, but cache data for next call. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # When called from within an eval, caching is not possible, so this routine | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # must not be called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub cgetargs (\@@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $sub = (caller(1))[3]; # Anomaly in caller(), will also get pkg name | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgetargs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | logcroak "can't call cgetargs from within an eval" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | if $sub =~ /^\(eval/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | _getargs(scalar(caller), 0, $sub, @_) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # xgetargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Like getargs(), but with extended specifications allowing to specify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # defaults for non-mandatory arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | sub xgetargs (\@@) { _getargs(scalar(caller), 1, "", @_) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xgetargs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # cxgetargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Like cgetargs(), but with extended specifications allowing to specify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # defaults for non-mandatory arguments. Be careful: those defaults are | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # deep-cloned and "frozen", so to speak. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # When called from within an eval, caching is not possible, so this routine | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # must not be called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub cxgetargs (\@@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 8 | ▶ | my $sub = (caller(1))[3]; # Anomaly in caller(), will also get pkg name | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cxgetargs: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | ▶ | logcroak "can't call cxgetargs from within an eval" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | if $sub =~ /^\(eval/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | _getargs(scalar(caller), 1, $sub, @_) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # _getargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Factorized work for *getargs() routines | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Our signature is: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # _getargs( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # # arguments added by our wrappers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # $callpkg, $extended, $subname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # # argument list to parse | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # \@x, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # # optional switches | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # -strict => 1, # unknown switches are fatal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # -inplace => 1, # edit \@x inplace: remove parsed args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # -ignorecase => 1, # override package's global | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # -extra => 0, # suppress return of extra arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # # argument definition list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # <variable> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # With: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # $callpkg Calling package | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # $extended Are they using x*getargs()? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # $subname Cache key, if we use it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Returns the list of values in the same order given in the definition list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # (the <variable> part), followed by the extra arguments we did not recognize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # with leading '-' removal and transformation to lowercase if ignorecase is on. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub _getargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 25 | ▶ | my ($callpkg, $extended, $subname, $args) = splice(@_, 0, 4); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getargs: called CC=91 SCAR=46.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 25 | ▶ | logconfess "first argument must be a reference to the argument list" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | unless ref $args eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # Check cache if told to do so. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 25 | ▶ | if ($subname ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 8 | my $sref = $subcache{$subname}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | if (defined $sref) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | logdbg 'info', "calling cached subroutine $sref"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | return &$sref($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | logdbg 'info', "no cached subroutine yet for $subname"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # Nothing in cache, or cache was disabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 19 | ▶ | my $case_insensitive = $ignore{$callpkg} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 19 | logdbg 'info', "case_insensitive=$case_insensitive for package $callpkg"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # If next argument is a HASH, then it's a set of extra switches that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # may alter our behaviour. Parse them manually. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Following are the defaults: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | my $strict = 1; # Fatal error on unknown switches | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 19 | my $inplace = 0; # No inplace editing of arguments | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 19 | my $extra; # Don't return extra args by default | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 19 | ▶ | if (ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 8 | my $swref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 8 | my %set = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | -strict => \$strict, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | -ignorecase => \$case_insensitive, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | -inplace => \$inplace, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | -extra => \$extra, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | ▶ | while (my ($sw, $val) = each %$swref) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | my $vset = $set{lc($sw)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | ▶ | logcroak "unknown switch $sw" unless ref $vset; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | $$vset = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # If they did not set -extra, compute suitable default: false | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # when -strict, true otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | ▶ | $extra = $strict ? 0 : 1 unless defined $extra; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # If strict, we ignore true settings for -inplace and -extra | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 8 | ▶ | if ($strict) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($inplace) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | logcarp "ignoring -inplace when -strict"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $inplace = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($extra) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | logcarp "ignoring -extra when -strict"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $extra = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # If we have one argument, it may be '[list]' or 'x'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # In extended mode, we must have an even amount of arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 19 | my @specs; # User specification list | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 19 | my $all_optional = 0; # True if all arguments are optional | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 19 | ▶ | if (@_ == 1 && ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and ref $_[0]
MC/DC50%1/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | ▶ | logcroak "must use an array reference for optional args" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | unless ref $_[0] eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | @specs = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | $all_optional = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 16 | @specs = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 16 | ▶ | logcroak "must supply an even amount of arguments in extend mode" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$extended and @specs % 2
MC/DC0%0/2
$extended and @specs % 2
$extended
@specs % 2
Truth table66%2/3
A and B
A= $extendedB= @specs % 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | if $extended && (@specs % 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Parse our argument list and compile it into @args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 19 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | my @args; # List of [name, type, is_optional, default] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 19 | ▶ | for (my $i = 0, my $step = $extended ? 2 : 1; $i < @specs; $i += $step) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 80 | my $arg = $specs[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 80 | my ($name, $type, $optional, $dflt); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 80 | ▶ | if ($extended) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 50 | $name = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 50 | my $spec = $specs[$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 50 | ▶ | if (ref $spec) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # Given as an array ref -> optional, with possible default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 35 | ▶ | logcroak "specs for optional '$name' are $spec, expected ARRAY" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | unless ref $spec eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 35 | ($type, $dflt) = @$spec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 35 | $optional = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # simple scalar is type, argument is mandatory | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 15 | $type = $spec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 15 | $optional = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Can be either "name" or "name=Type" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 30 | ($name, $type) = $arg =~ /^-?(\w+)=(\S+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 30 | ▶ | $name = $arg unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 30 | $optional = $all_optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 80 | ▶ | $name = lc($name) if $case_insensitive; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 80 | $name =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 80 | ▶ | logcroak "argument name cannot be empty" if $name eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 80 | ▶ | logcroak "argument name must be scalar, not $name" if ref $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 80 | ▶ | logcroak "duplicate argument definition for '$name'" if $seen{$name}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 80 | ▶ | push(@args, [ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | defined($type) ? $type : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $optional, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | defined($dflt) ? $dflt : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # If caching, generate the subroutine that will perform the checks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # We use logxcroak to report errors to the caller of the caller | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # of *getargs, i.e. the caller of the routine for which we're checking | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # the arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 19 | ▶ | if ($subname ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | my $lc = $case_insensitive ? 'lc' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | my $sub = &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | :sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | : my $aref_orig = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | : my @result; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | : my $cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | : my $isthere; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | : my $ctype; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | : local $Getargs::Long::dflt; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | : my $i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | : logxcroak 3, "expected an even number of arguments" if \@\$aref_orig % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | : my \%args = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | : (\$i++ % 2) ? \$_ : $lc(/^-/ ? substr(\$_, 1) : \$_) } \@\$aref_orig; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # Sanity check: no argument can be given twice | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | : spot_dups(\$aref_orig, $case_insensitive, 3) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | : if 2 * scalar(keys \%args) != \@\$aref_orig; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # Work on a copy if extra and no inplace | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | ▶ | if ($extra && !$inplace) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$extra and not $inplace
MC/DC0%0/2
$extra and not $inplace
$extra
not $inplace
Truth table33%1/3
A and not(B)
A= $extraB= not $inplace
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | : my $aref = [@$aref_orig]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | : my $aref = $aref_orig; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Index arguments if inplace editing or extra | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | if ($inplace || $extra) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inplace or $extra
MC/DC50%1/2
$inplace or $extra
$inplace
$extra
Truth table66%2/3
A or B
A= $inplaceB= $extra
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | : my $idx; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | : my %idx; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | : for (my $j = 0; $j < @$aref; $j += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | : my $key = $aref->[$j]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | : $key =~ s/^-//; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | $sub .= &q(<<'EOS') if $case_insensitive; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | : $key = lc($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | : $idx{$key} = $j; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | : } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | my ($name, $type, $optional, $dflt) = @$arg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | my $has_default = defined $dflt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | local $^W = 0; # Shut up Test::Harness | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | : # Argument [name=$name, type=$type, optional=$optional, dflt=$dflt] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | : \$cur = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | : \$isthere = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | : if (exists \$args{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | : \$isthere = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | : my \$val = delete \$args{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | : \$cur = \\\$val; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 10 | ▶ | $sub .= &q(<<EOS) if $inplace || $extra; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inplace or $extra
MC/DC50%1/2
$inplace or $extra
$inplace
$extra
Truth table66%2/3
A or B
A= $inplaceB= $extra
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | : # Splice argument out | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | : \$idx = \$idx{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 10 | ▶ | $sub .= &q(<<'EOS') if $inplace || $extra; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inplace or $extra
MC/DC50%1/2
$inplace or $extra
$inplace
$extra
Truth table66%2/3
A or B
A= $inplaceB= $extra
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | : splice(@$aref, $idx, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | : while (my ($k, $v) = each %idx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | : $idx{$k} -= 2 if $v > $idx; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | : } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 10 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | : } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 10 | ▶ | if ($optional) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 7 | ▶ | if ($has_default) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | : else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | : eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | : package Getargs::Long::_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | : no strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | : \$Getargs::Long::dflt = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 4 | my $obj = Data::Dumper->new([$dflt], []); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | $obj->Purity(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 4 | $sub .= $obj->Dumpxs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 4 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | : }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | : $cur = \$Getargs::Long::dflt; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | : } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | : logxcroak 3, "mandatory argument '$name' missing" unless \$isthere; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 10 | ▶ | if ($type ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 7 | ▶ | if ($optional) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 5 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | : logxcroak 3, "argument '$name' cannot be undef" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | : if \$isthere && !defined \$\$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | : logxcroak 3, "argument '$name' cannot be undef" unless defined \$\$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 7 | ▶ | my $opt_is_there = $optional ? "\$isthere &&" : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 7 | ▶ | if ($type =~ /^[isn]$/) { # Make sure it's a scalar | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # XXX Check that i is integer, s string and n natural | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | : logxcroak 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | : "argument '$name' must be scalar (type '$type') but is \$\$cur" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | : if $opt_is_there ref \$\$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | $sub .= &q(<<EOS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | : \$ctype = \$isthere ? ref \$\$cur : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | : logxcroak 3, "argument '$name' must be of type $type but is \$ctype" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | : if $opt_is_there (UNIVERSAL::isa(\$\$cur, 'UNIVERSAL') ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | : !\$\$cur->isa('$type') : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | : \$ctype ne '$type'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 10 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | : push(@result, defined($cur) ? $$cur : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # If we're strict, we must report unprocessed switches | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 2 | ▶ | $sub .= &q(<<'EOS') if $strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | : spot_unknown(\%args, 3) if scalar keys %args; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # Add extra unprocessed switches to the result list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2 | ▶ | $sub .= &q(<<'EOS') if $extra; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | : push(@result, @$aref); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | $sub .= &q(<<'EOS'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | : return @result; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | :} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | EOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | logdbg 'debug', "anonymous subroutine: $sub"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | ▶ | my $code = eval $sub; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2 | ▶ | if (chop($@)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | logerr "can't create subroutine for checking args of $subname: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | logwarn "ignoring caching directive for $subname"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 2 | $subcache{$subname} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | logdbg 'info', "calling newly built subroutine $code"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | return &$code($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # No caching made, perform validation by interpreting the structure | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # There is some unfortunate code duplication between the following checks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # and the above routine-construction logic. Some place are identical, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # but the main argument processing loop is noticeably different, even | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # though the same logic is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 17 | logdbg 'info', "interpreting structure to validate arguments"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 17 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | my $cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 17 | my $ctype; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 17 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 17 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 17 | ▶ | $args = [@$args] if $extra && !$inplace; # Work on a copy | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$extra and not $inplace
MC/DC50%1/2
$extra and not $inplace
$extra
not $inplace
Truth table66%2/3
A and not(B)
A= $extraB= not $inplace
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 17 | ▶ | logxcroak 2, "expected an even number of arguments" if @$args % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 17 | ▶ | if ($case_insensitive) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 10 | ▶ | %args = map { ($i++ % 2) ? $_ : lc(/^-/ ? substr($_, 1) : $_) } @$args; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 7 | ▶ | %args = map { ($i++ % 2) ? $_ : (/^-/ ? substr($_, 1) : $_) } @$args; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # Sanity check: no argument can be given twice | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 17 | ▶ | spot_dups($args, $case_insensitive, 2) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | if 2 * scalar(keys %args) != @$args; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # Index arguments if inplace editing or extra | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 17 | my %idx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 17 | ▶ | if ($inplace || $extra) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inplace or $extra
MC/DC100%2/2
$inplace or $extra
$inplace
$extra
Truth table100%3/3
A or B
A= $inplaceB= $extra
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 7 | ▶ | for (my $j = 0; $j < @$args; $j += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 19 | my $key = $args->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 19 | $key =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 19 | ▶ | $key = lc($key) if $case_insensitive; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 19 | $idx{$key} = $j; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # Process each argument | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 17 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 68 | my ($name, $type, $optional, $dflt) = @$arg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 68 | my $cur; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 68 | my $isthere = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 68 | ▶ | if (exists $args{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 50 | $isthere = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 50 | my $val = delete $args{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 50 | $cur = \$val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # Splice argument out if requested | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 50 | ▶ | if ($inplace || $extra) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inplace or $extra
MC/DC100%2/2
$inplace or $extra
$inplace
$extra
Truth table100%3/3
A or B
A= $inplaceB= $extra
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 17 | my $idx = $idx{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 17 | splice(@$args, $idx, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 17 | ▶ | while (my ($k, $v) = each %idx) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 53 | ▶ | $idx{$k} -= 2 if $v > $idx; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } elsif ($optional) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 15 | ▶ | $cur = \$dflt if defined $dflt; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 3 | logxcroak 2, "mandatory argument '$name' missing"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 65 | ▶ | push(@result, defined($cur) ? $$cur : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 65 | ▶ | next if !defined $type || $type eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $type or $type eq ""
MC/DC50%1/2
not defined $type or $type eq ""
not defined $type
$type eq ""
Truth table66%2/3
not(A) or B
A= not defined $typeB= $type eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 42 | ▶ | if ($optional) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 29 | ▶ | logxcroak 2, "argument '$name' cannot be undef" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$isthere and not defined $$cur
MC/DC0%0/2
$isthere and not defined $$cur
$isthere
not defined $$cur
Truth table66%2/3
A and not(B)
A= $isthereB= not defined $$cur
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | if $isthere && !defined $$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 13 | ▶ | logxcroak 2, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | "argument '$name' cannot be undef" unless defined $$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # XXX Check that i is integer, s string and n natural | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 41 | ▶ | if ($type =~ /^[isn]$/) { # Make sure it's a scalar | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 16 | ▶ | logxcroak 2, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
!$optional || $isthere and ref $$cur
not $optional or $isthere
MC/DC0%0/3
!$optional || $isthere and ref $$cur
not $optional
$isthere
ref $$cur
Truth table60%3/5
not(A) or B and C
A= not $optionalB= $isthereC= ref $$cur
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | "argument '$name' must be scalar (type '$type') but is $$cur" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | if (!$optional || $isthere) && ref $$cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 25 | ▶ | my $ctype = $isthere ? ref $$cur : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 25 | ▶ | logxcroak 2, "argument '$name' must be of type $type but is $ctype" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
!$optional || $isthere and UNIVERSAL::isa($$cur, "UNIVERSAL") ? !$$cur->isa($type) : $ctype ne $type
not $optional or $isthere
MC/DC66%2/3
!$optional || $isthere and UNIVERSAL::isa($$cur, "UNIVERSAL") ? !$$cur->isa($type) : $ctype ne $type
not $optional
$isthere
UNIVERSAL::isa($$cur, "UNIVERSAL") ? !$$cur->isa($type) : $ctype ne $type
Truth table80%4/5
not(A) or B and C
A= not $optionalB= $isthereC= UNIVERSAL::isa($$cur, "UNIVERSAL") ? !$$cur->isa($type) : $ctype ne $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | if (!$optional || $isthere) && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | (UNIVERSAL::isa($$cur, 'UNIVERSAL') ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | !$$cur->isa($type) : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | $ctype ne $type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # If we're strict, we must report unprocessed switches | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 12 | ▶ | spot_unknown(\%args, 2) if $strict && scalar keys %args; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$strict and scalar keys %args
MC/DC100%1/1
$strict and scalar keys %args
$strict
Truth table100%2/2
A
A= $strict
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # Add extra unprocessed switches to the result list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 8 | ▶ | push(@result, @$args) if $extra; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 8 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # spot_dups | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # Given a list of arguments in $aref, where we know there are duplicate "keys", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # identify them and croak by listing the culprits. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | sub spot_dups { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | my ($aref, $ignorecase, $level) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spot_dups: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | my @duplicates; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | for (my $i = 0; $i < @$aref; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | my $key = $ignorecase ? lc($aref->[$i]) : $aref->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $key =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | push(@duplicates, "-$key") if $seen{$key}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | logconfess "bug in Getargs::Long -- should have found duplicates" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | unless @duplicates; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | logxcroak ++$level, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | "multiple switches given for: " . join(", ", @duplicates); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # spot_unknown | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # Report keys held in supplied hashref as unknown switches. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | sub spot_unknown { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 5 | ▶ | my ($href, $level) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spot_unknown: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | my @unprocessed = map { "-$_" } keys %$href; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 5 | ▶ | my $es = @unprocessed == 1 ? '' : 'es'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 5 | logxcroak ++$level, "unknown switch$es: " . join(", ", @unprocessed); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | sub q { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 79 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
q: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 79 | s/^://gm; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 79 | return $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||