| 1 | 11 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | package Getopt::Lucid; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Clear, readable syntax for command line processing | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | our $VERSION = '1.08'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | our @EXPORT_OK = qw(Switch Counter Param List Keypair); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Getopt::Lucid::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Storable 2.16 qw(dclone); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Definitions | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | my $VALID_STARTCHAR = "a-zA-Z0-9"; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | my $VALID_CHAR = "a-zA-Z0-9_-"; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | my $VALID_LONG = qr/--[$VALID_STARTCHAR][$VALID_CHAR]*/; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | my $VALID_SHORT = qr/-[$VALID_STARTCHAR]/; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | my $VALID_BARE = qr/[$VALID_STARTCHAR][$VALID_CHAR]*/; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | my $VALID_NAME = qr/$VALID_LONG|$VALID_SHORT|$VALID_BARE/; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | my $SHORT_BUNDLE = qr/-[$VALID_STARTCHAR]{2,}/; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | my $NEGATIVE = qr/(?:--)?no-/; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | my @valid_keys = qw( name type default nocase valid needs canon ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | my @valid_types = qw( switch counter parameter list keypair); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub Switch { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 47 | ▶ | return bless { name => shift, type => 'switch' }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Switch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | "Getopt::Lucid::Spec"; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | sub Counter { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 23 | ▶ | return bless { name => shift, type => 'counter' }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Counter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | "Getopt::Lucid::Spec"; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | sub Param { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 34 | ▶ | my $self = { name => shift, type => 'parameter' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Param: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 34 | ▶ | $self->{valid} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 34 | return bless $self, "Getopt::Lucid::Spec"; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | sub List { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | my $self = { name => shift, type => 'list' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
List: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | $self->{valid} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | return bless $self, "Getopt::Lucid::Spec"; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | sub Keypair { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | ▶ | my $self = { name => shift, type => 'keypair' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Keypair: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 12 | ▶ | $self->{valid} = [ @_ ] if scalar @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | return bless $self, "Getopt::Lucid::Spec"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | package | ||||||||||||||||||||||||||||||||||||||||||
| 56 | Getopt::Lucid::Spec; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 11 | $Getopt::Lucid::Spec::VERSION = $Getopt::Lucid::VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # alternate way to specify validation | ||||||||||||||||||||||||||||||||||||||||||
| 60 | sub valid { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | Getopt::Lucid::throw_spec("valid() is not supported for '$self->{type}' options") | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | unless grep { $self->{type} eq $_ } qw/parameter list keypair/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | $self->{valid} = $self->{type} eq 'keypair' ? [ @_ ] : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub default { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 33 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 33 | my $type = $self->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 33 | ▶ | if ($self->{type} eq 'keypair') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $self->{default} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif ( @_ % 2 == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | $self->{default} = { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $self->{default} = []; # will cause an exception later | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ( $self->{type} eq 'list' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | $self->{default} = [ @_ ]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 24 | $self->{default} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 33 | return $self | |||||||||||||||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub anycase { my $self = shift; $self->{nocase}=1; return $self }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anycase: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | ▶ | sub needs { my $self = shift; $self->{needs}=[@_]; return $self }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
needs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | package Getopt::Lucid; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # new() | ||||||||||||||||||||||||||||||||||||||||||
| 99 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | my @params = qw/strict target/; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 189 | ▶ | my ($class, $spec, $target) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 189 | ▶ | my $args = ref($_[-1]) eq 'HASH' ? pop(@_) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 189 | ▶ | $args->{target} = ref($target) eq 'ARRAY' ? $target : \@ARGV; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 189 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 189 | $self->{$_} = $args->{$_} for @params; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 189 | $self->{raw_spec} = $spec; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 189 | ▶ | bless ($self, ref($class) ? ref($class) : $class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | throw_usage("Getopt::Lucid->new() requires an option specification array reference") | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 189 | ▶ | unless ref($self->{raw_spec}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 188 | _parse_spec($self); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 179 | _set_defaults($self); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 177 | $self->{options} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 177 | $self->{parsed} = []; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 177 | $self->{seen}{$_} = 0 for keys %{$self->{spec}}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 177 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # append_defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 123 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | sub append_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append_defaults: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | my %append = | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | ▶ | ref $_[0] eq 'HASH' ? %{+shift} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | (@_ % 2 == 0) ? @_ : | ||||||||||||||||||||||||||||||||||||||||||
| 130 | throw_usage("Argument to append_defaults() must be a hash or hash reference"); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | for my $name ( keys %{$self->{spec}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 132 | 50 | my $spec = $self->{spec}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 50 | my $strip = $self->{strip}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 50 | ▶ | next unless exists $append{$strip}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 29 | for ( $spec->{type} ) { | |||||||||||||||||||||||||||||||||||||||||
| 136 | 29 | ▶ | /switch|parameter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 15 | $self->{default}{$strip} = $append{$strip}; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 15 | last; | |||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 14 | ▶ | /counter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | $self->{default}{$strip} += $append{$strip}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 10 | ▶ | /list/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | throw_usage("Option '$strip' in append_defaults() must be scalar or array reference") | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | ▶ | if ref($append{$strip}) && ref($append{$strip}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $append{$strip} and ref $append{$strip} ne "ARRAY"
MC/DC100%2/2
ref $append{$strip} and ref $append{$strip} ne "ARRAY"
ref $append{$strip}
ref $append{$strip} ne "ARRAY"
Truth table100%3/3
A and B
A= ref $append{$strip}B= ref $append{$strip} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | $append{$strip} = ref($append{$strip}) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ? dclone( $append{$strip} ) | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | : [ $append{$strip} ] ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | push @{$self->{default}{$strip}}, @{$append{$strip}}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | /keypair/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | throw_usage("Option '$strip' in append_defaults() must be scalar or hash reference") | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | ▶ | if ref($append{$strip}) && ref($append{$strip}) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $append{$strip} and ref $append{$strip} ne "HASH"
MC/DC50%1/2
ref $append{$strip} and ref $append{$strip} ne "HASH"
ref $append{$strip}
ref $append{$strip} ne "HASH"
Truth table66%2/3
A and B
A= ref $append{$strip}B= ref $append{$strip} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | $self->{default}{$strip} = { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | %{$self->{default}{$strip}}, | |||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | %{$append{$strip}}, | |||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | throw_spec("Default '$spec->{canon}' = '$self->{default}{$strip}' fails to validate") | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 27 | ▶ | unless _validate_value($self, $self->{default}{$strip}, $spec->{valid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | _recalculate_options($self); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | return $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 171 | # defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 172 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | sub defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | return %{dclone($self->{default})}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # getopt() | ||||||||||||||||||||||||||||||||||||||||||
| 182 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | sub getopt { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 141 | ▶ | my ($self,$spec,$target) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getopt: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 141 | ▶ | if ( $self eq 'Getopt::Lucid' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | throw_usage("Getopt::Lucid->getopt() requires an option specification array reference") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | unless ref($spec) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | $self = new(@_) | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 140 | my (@passthrough); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 140 | ▶ | while (@{$self->{target}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 287 | my $raw = shift @{$self->{target}}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 287 | ▶ | last if $raw =~ /^--$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 272 | my ($orig, $val) = _split_equals($self, $raw); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 272 | ▶ | next if _unbundle($self, $orig, $val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 248 | ▶ | my $neg = $orig =~ s/^$NEGATIVE(.*)$/$1/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 248 | my $arg = _find_arg($self, $orig); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 248 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | $neg ? | ||||||||||||||||||||||||||||||||||||||||||
| 201 | $self->{seen}{$arg} = 0 : | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 232 | ▶ | $self->{seen}{$arg}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 232 | for ($self->{spec}{$arg}{type}) { | |||||||||||||||||||||||||||||||||||||||||
| 204 | 232 | ▶ | /switch/ ? _switch ($self, $arg, $val, $neg) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | /counter/ ? _counter ($self, $arg, $val, $neg) : | ||||||||||||||||||||||||||||||||||||||||||
| 206 | /parameter/ ? _parameter($self, $arg, $val, $neg) : | ||||||||||||||||||||||||||||||||||||||||||
| 207 | /list/ ? _list ($self, $arg, $val, $neg) : | ||||||||||||||||||||||||||||||||||||||||||
| 208 | /keypair/ ? _keypair ($self, $arg, $val, $neg) : | ||||||||||||||||||||||||||||||||||||||||||
| 209 | throw_usage("can't handle type '$_'"); | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 16 | ▶ | throw_argv("Invalid argument: $orig") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | if $orig =~ /^-./; # invalid if looks like it could be an arg; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | push @passthrough, $orig; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 103 | _recalculate_options($self); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 103 | @{$self->{target}} = (@passthrough, @{$self->{target}}); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 103 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 11 | ▶ | BEGIN { *getopts = \&getopt }; # handy alias | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # validate | ||||||||||||||||||||||||||||||||||||||||||
| 226 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | sub validate { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 83 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=9 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 83 | ▶ | throw_usage("Getopt::Lucid->validate() takes a hashref argument") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$arg and ref $arg ne "HASH"
MC/DC0%0/2
$arg and ref $arg ne "HASH"
$arg
ref $arg ne "HASH"
Truth table33%1/3
A and B
A= $argB= ref $arg ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | if $arg && ref($arg) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 83 | ▶ | if ( $arg && exists $arg->{requires} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$arg and exists $arg->{"requires"}
MC/DC50%1/2
$arg and exists $arg->{"requires"}
$arg
exists $arg->{"requires"}
Truth table66%2/3
A and B
A= $argB= exists $arg->{"requires"}
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | my $requires = $arg->{requires}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 7 | ▶ | throw_usage("'validate' argument 'requires' must be an array reference") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$requires and ref $requires ne "ARRAY"
MC/DC0%0/2
$requires and ref $requires ne "ARRAY"
$requires
ref $requires ne "ARRAY"
Truth table33%1/3
A and B
A= $requiresB= ref $requires ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | if $requires && ref($requires) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | for my $p ( @$requires ) { | |||||||||||||||||||||||||||||||||||||||||
| 238 | throw_argv("Required option '$self->{spec}{$p}{canon}' not found") | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | ▶ | if ( ! $self->{seen}{$p} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 81 | _check_prereqs($self); | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 76 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # merge_defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 250 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | sub merge_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_defaults: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | my %merge = | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 8 | ▶ | ref $_[0] eq 'HASH' ? %{+shift} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | (@_ % 2 == 0) ? @_ : | ||||||||||||||||||||||||||||||||||||||||||
| 257 | throw_usage("Argument to merge_defaults() must be a hash or hash reference"); | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 7 | for my $name ( keys %{$self->{spec}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 259 | 48 | my $spec = $self->{spec}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 48 | my $strip = $self->{strip}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 48 | ▶ | next unless exists $merge{$strip}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 29 | for ( $self->{spec}{$name}{type} ) { | |||||||||||||||||||||||||||||||||||||||||
| 263 | 29 | ▶ | /switch|counter|parameter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 19 | $self->{default}{$strip} = $merge{$strip}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 19 | last; | |||||||||||||||||||||||||||||||||||||||||
| 266 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 10 | ▶ | /list/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | throw_usage("Option '$strip' in merge_defaults() must be scalar or array reference") | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 5 | ▶ | if ref($merge{$strip}) && ref($merge{$strip}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $merge{$strip} and ref $merge{$strip} ne "ARRAY"
MC/DC100%2/2
ref $merge{$strip} and ref $merge{$strip} ne "ARRAY"
ref $merge{$strip}
ref $merge{$strip} ne "ARRAY"
Truth table100%3/3
A and B
A= ref $merge{$strip}B= ref $merge{$strip} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | $merge{$strip} = ref($merge{$strip}) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 271 | ? dclone( $merge{$strip} ) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | ▶ | : [ $merge{$strip} ] ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | $self->{default}{$strip} = $merge{$strip}; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 5 | ▶ | /keypair/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | throw_usage("Option '$strip' in merge_defaults() must be scalar or hash reference") | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | if ref($merge{$strip}) && ref($merge{$strip}) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $merge{$strip} and ref $merge{$strip} ne "HASH"
MC/DC50%1/2
ref $merge{$strip} and ref $merge{$strip} ne "HASH"
ref $merge{$strip}
ref $merge{$strip} ne "HASH"
Truth table66%2/3
A and B
A= ref $merge{$strip}B= ref $merge{$strip} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | $self->{default}{$strip} = dclone($merge{$strip}); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||
| 281 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | throw_spec("Default '$spec->{canon}' = '$self->{default}{$strip}' fails to validate") | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 27 | ▶ | unless _validate_value($self, $self->{default}{$strip}, $spec->{valid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | _recalculate_options($self); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | return $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 291 | # names() | ||||||||||||||||||||||||||||||||||||||||||
| 292 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | sub names { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | return values %{$self->{strip}}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # options() | ||||||||||||||||||||||||||||||||||||||||||
| 302 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | sub options { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 122 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 122 | return %{dclone($self->{options})}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # replace_defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 311 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | sub replace_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replace_defaults: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | my %replace = | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 8 | ▶ | ref $_[0] eq 'HASH' ? %{+shift} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | (@_ % 2 == 0) ? @_ : | ||||||||||||||||||||||||||||||||||||||||||
| 318 | throw_usage("Argument to replace_defaults() must be a hash or hash reference"); | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | for my $name ( keys %{$self->{spec}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 320 | 51 | my $spec = $self->{spec}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 51 | my $strip = $self->{strip}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 51 | for ( $self->{spec}{$name}{type} ) { | |||||||||||||||||||||||||||||||||||||||||
| 323 | 51 | ▶ | /switch|counter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 16 | ▶ | $self->{default}{$strip} = $replace{$strip} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$replace{$strip} || 0
MC/DC100%1/1
$replace{$strip} || 0
$replace{$strip}
Truth table100%2/2
A
A= $replace{$strip}
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 16 | last; | |||||||||||||||||||||||||||||||||||||||||
| 326 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 35 | ▶ | /parameter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 22 | $self->{default}{$strip} = $replace{$strip}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 22 | last; | |||||||||||||||||||||||||||||||||||||||||
| 330 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 13 | ▶ | /list/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | throw_usage("Option '$strip' in replace_defaults() must be scalar or array reference") | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 6 | ▶ | if ref($replace{$strip}) && ref($replace{$strip}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $replace{$strip} and ref $replace{$strip} ne "ARRAY"
MC/DC100%2/2
ref $replace{$strip} and ref $replace{$strip} ne "ARRAY"
ref $replace{$strip}
ref $replace{$strip} ne "ARRAY"
Truth table100%3/3
A and B
A= ref $replace{$strip}B= ref $replace{$strip} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 5 | ▶ | if ( exists $replace{$strip} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | $replace{$strip} = ref($replace{$strip}) eq 'ARRAY' ? | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 4 | ▶ | $replace{$strip} : [ $replace{$strip} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | $replace{$strip} = []; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | $self->{default}{$strip} = dclone($replace{$strip}); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||
| 342 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | ▶ | /keypair/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | throw_usage("Option '$strip' in replace_defaults() must be scalar or hash reference") | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | ▶ | if ref($replace{$strip}) && ref($replace{$strip}) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $replace{$strip} and ref $replace{$strip} ne "HASH"
MC/DC100%2/2
ref $replace{$strip} and ref $replace{$strip} ne "HASH"
ref $replace{$strip}
ref $replace{$strip} ne "HASH"
Truth table100%3/3
A and B
A= ref $replace{$strip}B= ref $replace{$strip} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | ▶ | $replace{$strip} = {} unless exists $replace{$strip}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | $self->{default}{$strip} = dclone($replace{$strip}); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | last; | |||||||||||||||||||||||||||||||||||||||||
| 349 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | throw_spec("Default '$spec->{canon}' = '$self->{default}{$strip}' fails to validate") | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 49 | ▶ | unless _validate_value($self, $self->{default}{$strip}, $spec->{valid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 4 | _recalculate_options($self); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | return $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # reset_defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 360 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | sub reset_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 6 | _set_defaults($self); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 6 | _recalculate_options($self); | |||||||||||||||||||||||||||||||||||||||||
| 366 | 6 | return $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # _check_prereqs() | ||||||||||||||||||||||||||||||||||||||||||
| 371 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | sub _check_prereqs { | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 81 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_prereqs: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 81 | for my $key ( keys %{$self->{seen}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 376 | 205 | ▶ | next unless $self->{seen}{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 105 | ▶ | next unless exists $self->{spec}{$key}{needs}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 10 | for (@{$self->{spec}{$key}{needs}}) { | |||||||||||||||||||||||||||||||||||||||||
| 379 | throw_argv("Option '$self->{spec}{$key}{canon}' ". | ||||||||||||||||||||||||||||||||||||||||||
| 380 | "requires option '$self->{spec}{$_}{canon}'") | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 12 | ▶ | unless $self->{seen}{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 387 | # _counter() | ||||||||||||||||||||||||||||||||||||||||||
| 388 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | sub _counter { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 82 | ▶ | my ($self, $arg, $val, $neg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_counter: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 82 | ▶ | throw_argv("Counter option can't take a value: $self->{spec}{$arg}{canon}=$val") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | if defined $val; | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 80 | push @{$self->{parsed}}, [ $arg, 1, $neg ]; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # _find_arg() | ||||||||||||||||||||||||||||||||||||||||||
| 399 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | sub _find_arg { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 344 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_arg: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 344 | ▶ | $arg =~ s/^-*// unless $self->{strict}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 344 | ▶ | return $self->{alias_hr}{$arg} if exists $self->{alias_hr}{$arg}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 66 | for ( keys %{$self->{alias_nocase}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 408 | 14 | ▶ | return $self->{alias_nocase}{$_} if $arg =~ /^$_$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 62 | return; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # _keypair() | ||||||||||||||||||||||||||||||||||||||||||
| 416 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | sub _keypair { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 24 | ▶ | my ($self, $arg, $val, $neg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keypair: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 24 | my ($key, $data); | |||||||||||||||||||||||||||||||||||||||||
| 421 | 24 | ▶ | if ($neg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 4 | $key = $val; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 20 | ▶ | my $value = defined $val ? $val : shift @{$self->{target}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 20 | ▶ | if (! defined $val && ! defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $val or defined $value
MC/DC100%2/2
defined $val or defined $value
defined $val
defined $value
Truth table100%3/3
A or B
A= defined $valB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | throw_argv("Option '$self->{spec}{$arg}{canon}' requires a value"); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 19 | ▶ | throw_argv("Badly formed keypair for '$self->{spec}{$arg}{canon}'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | unless $value =~ /[^=]+=.+/; | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 16 | ($key, $data) = ( $value =~ /^([^=]*)=(.*)$/ ) ; | |||||||||||||||||||||||||||||||||||||||||
| 433 | throw_argv("Invalid keypair '$self->{spec}{$arg}{canon}': $key => $data") | ||||||||||||||||||||||||||||||||||||||||||
| 434 | unless _validate_value($self, { $key => $data }, | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 16 | ▶ | $self->{spec}{$arg}{valid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 16 | push @{$self->{parsed}}, [ $arg, [ $key, $data ], $neg ]; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 441 | # _list() | ||||||||||||||||||||||||||||||||||||||||||
| 442 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | sub _list { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 20 | ▶ | my ($self, $arg, $val, $neg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 20 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 20 | ▶ | if ($neg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 4 | $value = $val; | |||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 16 | ▶ | $value = defined $val ? $val : shift @{$self->{target}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 16 | ▶ | if (! defined $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 13 | ▶ | if (! defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | throw_argv("Option '$self->{spec}{$arg}{canon}' requires a value"); | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 12 | $value =~ s/^$NEGATIVE(.*)$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 15 | ▶ | throw_argv("Ambiguous value for $self->{spec}{$arg}{canon} could be option: $value") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $val and _find_arg($self, $value)
MC/DC100%2/2
not defined $val and _find_arg($self, $value)
not defined $val
_find_arg($self, $value)
Truth table100%3/3
not(A) and B
A= not defined $valB= _find_arg($self, $value)
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | if ! defined $val and _find_arg($self, $value); | ||||||||||||||||||||||||||||||||||||||||||
| 461 | throw_argv("Invalid list option $self->{spec}{$arg}{canon} = $value") | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 14 | ▶ | unless _validate_value($self, $value, $self->{spec}{$arg}{valid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 17 | push @{$self->{parsed}}, [ $arg, $value, $neg ]; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # _parameter() | ||||||||||||||||||||||||||||||||||||||||||
| 469 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | sub _parameter { | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 52 | ▶ | my ($self, $arg, $val, $neg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parameter: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 52 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 52 | ▶ | if ($neg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 6 | ▶ | throw_argv("Negated parameter option can't take a value: $self->{spec}{$arg}{canon}=$val") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | if defined $val; | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 46 | ▶ | $value = defined $val ? $val : shift @{$self->{target}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 46 | ▶ | if (! defined $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 39 | ▶ | if (! defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 2 | throw_argv("Option '$self->{spec}{$arg}{canon}' requires a value"); | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 37 | $value =~ s/^$NEGATIVE(.*)$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 44 | ▶ | throw_argv("Ambiguous value for $self->{spec}{$arg}{canon} could be option: $value") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $val and _find_arg($self, $value)
MC/DC100%2/2
not defined $val and _find_arg($self, $value)
not defined $val
_find_arg($self, $value)
Truth table100%3/3
not(A) and B
A= not defined $valB= _find_arg($self, $value)
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | if ! defined $val and _find_arg($self, $value); | ||||||||||||||||||||||||||||||||||||||||||
| 488 | throw_argv("Invalid parameter $self->{spec}{$arg}{canon} = $value") | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 41 | ▶ | unless _validate_value($self, $value, $self->{spec}{$arg}{valid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 42 | push @{$self->{parsed}}, [ $arg, $value, $neg ]; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # _parse_spec() | ||||||||||||||||||||||||||||||||||||||||||
| 496 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | sub _parse_spec { | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 188 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_spec: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 188 | my $spec = $self->{raw_spec}; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 188 | for my $opt ( @$spec ) { | |||||||||||||||||||||||||||||||||||||||||
| 502 | 534 | my $name = $opt->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 534 | my @names = split( /\|/, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 504 | 534 | $opt->{canon} = $names[0]; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 534 | _validate_spec($self,\@names,$opt); | |||||||||||||||||||||||||||||||||||||||||
| 506 | 526 | ▶ | @names = map { s/^-*//; $_ } @names unless $self->{strict}; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 526 | for (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 508 | 840 | $self->{alias_hr}{$_} = $names[0]; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 840 | ▶ | $self->{alias_nocase}{$_} = $names[0] if $opt->{nocase}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 526 | $self->{spec}{$names[0]} = $opt; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 526 | ($self->{strip}{$names[0]} = $names[0]) =~ s/^-+//; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 180 | _validate_prereqs($self); | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 518 | # _recalculate_options() | ||||||||||||||||||||||||||||||||||||||||||
| 519 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | sub _recalculate_options { | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 121 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_recalculate_options: called CC=18 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 121 | my %result; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 121 | for my $k ( keys %{$self->{default}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 525 | 463 | my $d = $self->{default}{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 463 | ▶ | $result{$k} = ref($d) eq 'ARRAY' ? [ @$d ] : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | ref($d) eq 'HASH' ? { %$d } : $d; | ||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 121 | for my $opt ( @{$self->{parsed}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 530 | 274 | my ($name, $value, $neg) = @$opt; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 274 | for ($self->{spec}{$name}{type}) { | |||||||||||||||||||||||||||||||||||||||||
| 532 | 274 | my $strip = $self->{strip}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 274 | ▶ | /switch/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 59 | ▶ | $result{$strip} = $neg ? 0 : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 59 | last; | |||||||||||||||||||||||||||||||||||||||||
| 536 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 215 | ▶ | /counter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 102 | ▶ | $result{$strip} = $neg ? 0 : $result{$strip} + $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 102 | last; | |||||||||||||||||||||||||||||||||||||||||
| 540 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 113 | ▶ | /parameter/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 42 | ▶ | $result{$strip} = $neg ? "" : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 42 | last; | |||||||||||||||||||||||||||||||||||||||||
| 544 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 71 | ▶ | /list/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 40 | ▶ | if ($neg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | $result{$strip} = $value ? | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 4 | ▶ | [ grep { $_ ne $value } @{$result{$strip}} ] : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | []; | ||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 36 | else { push @{$result{$strip}}, $value } | |||||||||||||||||||||||||||||||||||||||||
| 552 | 40 | last; | |||||||||||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 31 | ▶ | /keypair/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 31 | ▶ | if ($neg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 4 | ▶ | if ($value->[0]) { delete $result{$strip}{$value->[0]} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 2 | else { $result{$strip} = {} } | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 27 | else { $result{$strip}{$value->[0]} = $value->[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 31 | last; | |||||||||||||||||||||||||||||||||||||||||
| 561 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 121 | return $self->{options} = \%result; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 568 | # _regex_or_code | ||||||||||||||||||||||||||||||||||||||||||
| 569 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | sub _regex_or_code { | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 174 | ▶ | my ($value,$valid) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_or_code: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 174 | ▶ | return 1 unless defined $valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 171 | ▶ | if ( ref($valid) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 10 | local $_ = $value; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 10 | return $valid->($value); | |||||||||||||||||||||||||||||||||||||||||
| 577 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 161 | return $value =~ /^$valid$/; | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 583 | # _set_defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 584 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | sub _set_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 185 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_defaults: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 185 | my %default; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 185 | for my $k ( keys %{$self->{spec}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 590 | 581 | my $spec = $self->{spec}{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 581 | ▶ | my $d = exists ($spec->{default}) ? $spec->{default} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 581 | my $type = $self->{spec}{$k}{type}; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 581 | my $strip = $self->{strip}{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 581 | ▶ | throw_spec("Default for list '$spec->{canon}' must be array reference") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type eq "list" and defined $d and ref $d ne "ARRAY"
$type eq "list" and defined $d
MC/DC0%0/3
$type eq "list" and defined $d and ref $d ne "ARRAY"
$type eq "list"
defined $d
ref $d ne "ARRAY"
Truth table75%3/4
A and B and C
A= $type eq "list"B= defined $dC= ref $d ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | if ( $type eq "list" && defined $d && ref($d) ne "ARRAY" ); | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 581 | ▶ | throw_spec("Default for keypair '$spec->{canon}' must be hash reference") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$type eq "keypair" and defined $d and ref $d ne "HASH"
$type eq "keypair" and defined $d
MC/DC100%3/3
$type eq "keypair" and defined $d and ref $d ne "HASH"
$type eq "keypair"
defined $d
ref $d ne "HASH"
Truth table100%4/4
A and B and C
A= $type eq "keypair"B= defined $dC= ref $d ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | if ( $type eq "keypair" && defined $d && ref($d) ne "HASH" ); | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 580 | ▶ | if (defined $d) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | throw_spec("Default '$spec->{canon}' = '$d' fails to validate") | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 217 | ▶ | unless _validate_value($self, $d, $spec->{valid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 579 | $default{$strip} = do { | |||||||||||||||||||||||||||||||||||||||||
| 603 | 579 | local $_ = $type; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 579 | ▶ | /switch/ ? (defined $d ? $d: 0) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | /counter/ ? (defined $d ? $d: 0) : | ||||||||||||||||||||||||||||||||||||||||||
| 606 | /parameter/ ? $d : | ||||||||||||||||||||||||||||||||||||||||||
| 607 | /list/ ? (defined $d ? dclone($d): []) : | ||||||||||||||||||||||||||||||||||||||||||
| 608 | /keypair/ ? (defined $d ? dclone($d): {}) : | ||||||||||||||||||||||||||||||||||||||||||
| 609 | undef; | ||||||||||||||||||||||||||||||||||||||||||
| 610 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 183 | $self->{default} = \%default; | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 616 | # _split_equals() | ||||||||||||||||||||||||||||||||||||||||||
| 617 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | sub _split_equals { | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 272 | ▶ | my ($self,$raw) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_equals: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 272 | my ($arg,$val); | |||||||||||||||||||||||||||||||||||||||||
| 622 | 272 | ▶ | if ( $raw =~ /^($NEGATIVE?$VALID_NAME|$SHORT_BUNDLE)=(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 27 | $arg = $1; | |||||||||||||||||||||||||||||||||||||||||
| 624 | 27 | $val = $2; | |||||||||||||||||||||||||||||||||||||||||
| 625 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 245 | $arg = $raw; | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 272 | return ($arg, $val); | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 632 | # _switch() | ||||||||||||||||||||||||||||||||||||||||||
| 633 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | sub _switch { | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 54 | ▶ | my ($self, $arg, $val, $neg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_switch: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 54 | ▶ | throw_argv("Switch can't take a value: $self->{spec}{$arg}{canon}=$val") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | if defined $val; | ||||||||||||||||||||||||||||||||||||||||||
| 639 | 52 | ▶ | if (! $neg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | throw_argv("Switch used twice: $self->{spec}{$arg}{canon}") | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 48 | ▶ | if $self->{seen}{$arg} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 51 | push @{$self->{parsed}}, [ $arg, 1, $neg ]; | |||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 647 | # _unbundle() | ||||||||||||||||||||||||||||||||||||||||||
| 648 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | sub _unbundle { | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 272 | ▶ | my ($self,$arg, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unbundle: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 272 | ▶ | if ( $arg =~ /^$SHORT_BUNDLE$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 24 | my @flags = split(//,substr($arg,1)); | |||||||||||||||||||||||||||||||||||||||||
| 654 | 24 | ▶ | unshift @{$self->{target}}, ("-" . pop(@flags) . "=" . $val) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | if defined $val; | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 24 | for ( reverse @flags ) { | |||||||||||||||||||||||||||||||||||||||||
| 657 | 61 | unshift @{$self->{target}}, "-$_"; | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 248 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 665 | # _validate_prereqs() | ||||||||||||||||||||||||||||||||||||||||||
| 666 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | sub _validate_prereqs { | ||||||||||||||||||||||||||||||||||||||||||
| 669 | 180 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_prereqs: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 180 | for my $key ( keys %{$self->{spec}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 671 | 523 | ▶ | next unless exists $self->{spec}{$key}{needs}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 18 | my $needs = $self->{spec}{$key}{needs}; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 18 | ▶ | my @prereq = ref($needs) eq 'ARRAY' ? @$needs : ( $needs ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 18 | for (@prereq) { | |||||||||||||||||||||||||||||||||||||||||
| 675 | 24 | ▶ | throw_spec("Prerequisite '$_' for '$self->{spec}{$key}{canon}' is not recognized") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | unless _find_arg($self,$_); | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 23 | $_ = _find_arg($self,$_); | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 17 | $self->{spec}{$key}{needs} = \@prereq; | |||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 685 | # _validate_spec() | ||||||||||||||||||||||||||||||||||||||||||
| 686 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | sub _validate_spec { | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 534 | ▶ | my ($self,$names,$details) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_spec: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 534 | for my $name ( @$names ) { | |||||||||||||||||||||||||||||||||||||||||
| 691 | 849 | my $alt_name = $name; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 849 | ▶ | $alt_name =~ s/^-*// unless $self->{strict}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | 849 | ▶ | throw_spec( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | "'$name' is not a valid option name/alias" | ||||||||||||||||||||||||||||||||||||||||||
| 695 | ) unless $name =~ /^$VALID_NAME$/; | ||||||||||||||||||||||||||||||||||||||||||
| 696 | throw_spec( | ||||||||||||||||||||||||||||||||||||||||||
| 697 | "'$name' is not unique" | ||||||||||||||||||||||||||||||||||||||||||
| 698 | 847 | ▶ | ) if exists $self->{alias_hr}{$alt_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 844 | my $strip; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 844 | ($strip = $name) =~ s/^-+//; | |||||||||||||||||||||||||||||||||||||||||
| 701 | throw_spec( | ||||||||||||||||||||||||||||||||||||||||||
| 702 | "'$strip' conflicts with other options" | ||||||||||||||||||||||||||||||||||||||||||
| 703 | 844 | ▶ | ) if grep { $strip eq $_ } values %{$self->{strip}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 529 | for my $key ( keys %$details ) { | |||||||||||||||||||||||||||||||||||||||||
| 706 | throw_spec( | ||||||||||||||||||||||||||||||||||||||||||
| 707 | "'$key' is not a valid option specification key" | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 1882 | ▶ | ) unless grep { $key eq $_ } @valid_keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 528 | my $type = $details->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 711 | throw_spec( | ||||||||||||||||||||||||||||||||||||||||||
| 712 | "'$type' is not a valid option type" | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 528 | ▶ | ) unless grep { $type eq $_ } @valid_types; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 717 | # _validate_value() | ||||||||||||||||||||||||||||||||||||||||||
| 718 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | sub _validate_value { | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 391 | ▶ | my ($self, $value, $valid) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_value: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 391 | ▶ | return 1 unless defined $valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 102 | ▶ | if ( ref($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 30 | my $valid_key = $valid->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 725 | 30 | my $valid_val = $valid->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 726 | 30 | ▶ | while (my ($k,$v) = each %$value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 44 | ▶ | _regex_or_code($k, $valid_key) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 42 | ▶ | _regex_or_code($v, $valid_val) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 26 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 731 | } elsif ( ref($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 20 | for (@$value) { | |||||||||||||||||||||||||||||||||||||||||
| 733 | 36 | ▶ | _regex_or_code($_, $valid) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 736 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 52 | return _regex_or_code($value, $valid); | |||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 742 | # AUTOLOAD() | ||||||||||||||||||||||||||||||||||||||||||
| 743 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 204 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 204 | my $name = $Getopt::Lucid::AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 748 | 204 | $name =~ s/.*:://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||||||
| 749 | 204 | ▶ | return if $name eq "DESTROY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 15 | my ($action, $maybe_opt) = $name =~ /^(get|set)_(.+)/ ; | |||||||||||||||||||||||||||||||||||||||||
| 751 | 15 | ▶ | if ($action) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | # look for a match | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 15 | my $opt; | |||||||||||||||||||||||||||||||||||||||||
| 754 | SEARCH: | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 15 | for my $known_opt ( values %{ $self->{strip} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 756 | 45 | ▶ | if ( $maybe_opt eq $known_opt ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | 12 | $opt = $known_opt; | |||||||||||||||||||||||||||||||||||||||||
| 758 | 12 | last SEARCH; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | # try without dashes | ||||||||||||||||||||||||||||||||||||||||||
| 761 | 33 | (my $fuzzy_opt = $known_opt) =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 762 | 33 | ▶ | if ( $maybe_opt eq $fuzzy_opt ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 3 | $opt = $known_opt; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 3 | last SEARCH; | |||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | # throw if no valid option was found | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 15 | ▶ | throw_usage("Can't $action unknown option '$maybe_opt'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | if ! $opt; | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | # handle the accessor if an option was found | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 15 | ▶ | if ($action eq "set") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | $self->{options}{$opt} = | ||||||||||||||||||||||||||||||||||||||||||
| 775 | ref($self->{options}{$opt}) eq 'ARRAY' ? [@_] : | ||||||||||||||||||||||||||||||||||||||||||
| 776 | 5 | ▶ | ref($self->{options}{$opt}) eq 'HASH' ? {@_} : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 15 | my $ans = $self->{options}{$opt}; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 15 | ▶ | return ref($ans) eq 'ARRAY' ? @$ans : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | ref($ans) eq 'HASH' ? %$ans : $ans; | ||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $super = "SUPER::$name"; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $self->$super(@_); | |||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 11 | 1; # modules must be true | |||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | __END__ | ||||||||||||||||||||||||||||||||||||||||||