| 1 | package Smart::Options; | ||||||||||||||||||||||||||||||||||
| 2 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 21 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 21 | require Exporter; | |||||||||||||||||||||||||||||||||
| 8 | 21 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||
| 9 | 21 | our @EXPORT = qw(argv); | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use List::Util 1.45 qw(uniq); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 21 | ▶ | use Text::Table; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 64 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 15 | 64 | my $pkg = shift; | |||||||||||||||||||||||||||||||||
| 16 | 64 | my %opt = @_; | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 64 | my $self = bless { | |||||||||||||||||||||||||||||||||
| 19 | alias => {}, | ||||||||||||||||||||||||||||||||||
| 20 | default => {}, | ||||||||||||||||||||||||||||||||||
| 21 | boolean => {}, | ||||||||||||||||||||||||||||||||||
| 22 | demand => {}, | ||||||||||||||||||||||||||||||||||
| 23 | usage => "Usage: $0", | ||||||||||||||||||||||||||||||||||
| 24 | describe => {}, | ||||||||||||||||||||||||||||||||||
| 25 | type => {}, | ||||||||||||||||||||||||||||||||||
| 26 | subcmd => {}, | ||||||||||||||||||||||||||||||||||
| 27 | coerce => {}, | ||||||||||||||||||||||||||||||||||
| 28 | env => {}, | ||||||||||||||||||||||||||||||||||
| 29 | env_prefix => '', | ||||||||||||||||||||||||||||||||||
| 30 | }, $pkg; | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 64 | ▶ | if ($opt{add_help} // 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$opt{"add_help"} // 1
MC/DC100%1/1
$opt{"add_help"} // 1
$opt{"add_help"}
Truth table100%2/2
A
A= $opt{"add_help"}
| |||||||||||||||||||||||||||||||||||
| 33 | 61 | $self->options(h => { | |||||||||||||||||||||||||||||||||
| 34 | alias => 'help', | ||||||||||||||||||||||||||||||||||
| 35 | describe => 'show help', | ||||||||||||||||||||||||||||||||||
| 36 | }); | ||||||||||||||||||||||||||||||||||
| 37 | 61 | $self->{add_help} = 1; | |||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 64 | $self; | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | sub argv { | ||||||||||||||||||||||||||||||||
|
Subroutine
argv: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 44 | 12 | Smart::Options->new->parse(@_); | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 235 | ▶ | sub _set { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 48 | 235 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 49 | 235 | my $param = shift; | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 235 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 52 | 235 | for my $option (keys %args) { | |||||||||||||||||||||||||||||||||
| 53 | 236 | $self->{$param}->{$option} = $args{$option}; | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 235 | $self; | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 91 | ▶ | sub alias { shift->_set('alias', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | sub default { shift->_set('default', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 61 | 64 | ▶ | sub describe { shift->_set('describe', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
describe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 62 | 69 | ▶ | sub type { shift->_set('type', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | sub subcmd { shift->_set('subcmd', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
subcmd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 14 | ▶ | sub _set_flag { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_flag: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 66 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 67 | 14 | my $param = shift; | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 14 | for my $option (@_) { | |||||||||||||||||||||||||||||||||
| 70 | 23 | $self->{$param}->{$option} = 1; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 14 | $self; | |||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub boolean { shift->_set_flag('boolean', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
boolean: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 77 | 9 | ▶ | sub demand { shift->_set_flag('demand', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
demand: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub env { shift->_set_flag('env', @_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 62 | ▶ | sub options { | ||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 81 | 62 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 62 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 84 | 62 | ▶ | while (my($opt, $setting) = each %args) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | 62 | for my $key (keys %$setting) { | |||||||||||||||||||||||||||||||||
| 86 | 125 | $self->$key($opt, $setting->{$key}); | |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 62 | $self; | |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 32 | ▶ | sub coerce { | ||||||||||||||||||||||||||||||||
|
Subroutine
coerce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 94 | 32 | my ($self, $isa, $type, $generater) = @_; | |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 32 | $self->{coerce}->{$isa} = { | |||||||||||||||||||||||||||||||||
| 97 | type => $type, | ||||||||||||||||||||||||||||||||||
| 98 | generater => $generater, | ||||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 32 | $self; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | sub usage { $_[0]->{usage} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | sub env_prefix { $_[0]->{env_prefix} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||
|
Subroutine
env_prefix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 13 | ▶ | sub _get_opt_desc { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_opt_desc: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 108 | 13 | my ($self, $option) = @_; | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 13 | my @opts = ($option); | |||||||||||||||||||||||||||||||||
| 111 | 13 | ▶ | while ( my($opt, $val) = each %{$self->{alias}} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 17 | ▶ | push @opts, $opt if $val eq $option; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | return join(', ', map { (length($_) == 1 ? '-' : '--') . $_ } sort @opts); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 13 | ▶ | sub _get_describe { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_describe: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||
| 119 | 13 | my ($self, $option) = @_; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 13 | my $desc = $self->{describe}->{$option}; | |||||||||||||||||||||||||||||||||
| 122 | 13 | ▶ | while ( my($opt, $val) = each %{$self->{alias}} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | 17 | ▶ | $desc ||= $self->{describe}->{$opt} if $val eq $option; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$desc ||= $self->{"describe"}{$opt}
MC/DC100%2/2
$desc ||= $self->{"describe"}{$opt}
$desc
$self->{"describe"}{$opt}
Truth table100%3/3
A ||= B
A= $descB= $self->{"describe"}{$opt}
| |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 13 | ▶ | return $desc ? ucfirst($desc) : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 14 | ▶ | sub _get_default { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_default: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 130 | 14 | my ($self, $option) = @_; | |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 14 | my $value = $self->{default}->{$option}; | |||||||||||||||||||||||||||||||||
| 133 | 14 | ▶ | while ( my($opt, $val) = each %{$self->{alias}} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | 18 | ▶ | $value ||= $self->{default}->{$opt} if $val eq $option; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value ||= $self->{"default"}{$opt}
MC/DC50%1/2
$value ||= $self->{"default"}{$opt}
$value
$self->{"default"}{$opt}
Truth table66%2/3
A ||= B
A= $valueB= $self->{"default"}{$opt}
| |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 14 | $value; | |||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | sub help { | ||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 141 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 6 | my $alias = $self->{alias}; | |||||||||||||||||||||||||||||||||
| 144 | 6 | my $demand = $self->{demand}; | |||||||||||||||||||||||||||||||||
| 145 | 6 | my $describe = $self->{describe}; | |||||||||||||||||||||||||||||||||
| 146 | 6 | my $default = $self->{default}; | |||||||||||||||||||||||||||||||||
| 147 | 6 | my $boolean = $self->{boolean}; | |||||||||||||||||||||||||||||||||
| 148 | 6 | my $help = $self->{usage} . "\n"; | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 6 | ▶ | if (scalar(keys %$demand) or scalar(keys %$describe)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
scalar keys %$demand or scalar keys %$describe
MC/DC100%1/1
scalar keys %$demand or scalar keys %$describe
scalar keys %$demand
Truth table100%2/2
A
A= scalar keys %$demand
| |||||||||||||||||||||||||||||||||||
| 151 | 6 | my @opts; | |||||||||||||||||||||||||||||||||
| 152 | 6 | for my $opt (uniq sort keys %$demand, keys %$describe, keys %$default, keys %$boolean, values %$alias) { | |||||||||||||||||||||||||||||||||
| 153 | 17 | ▶ | next if $alias->{$opt}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 154 | push @opts, [ | ||||||||||||||||||||||||||||||||||
| 155 | $self->_get_opt_desc($opt), | ||||||||||||||||||||||||||||||||||
| 156 | $self->_get_describe($opt), | ||||||||||||||||||||||||||||||||||
| 157 | $boolean->{$opt} ? '[boolean]' : '', | ||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | $demand->{$opt} ? '[required]' : '', | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 159 | 1 | $self->_get_default($opt) ? "[default: @{[$self->_get_default($opt)]}]" : '', | |||||||||||||||||||||||||||||||||
| 160 | ]; | ||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 6 | my $sep = \' '; | |||||||||||||||||||||||||||||||||
| 164 | 6 | $help .= "\nOptions:\n"; | |||||||||||||||||||||||||||||||||
| 165 | 6 | $help .= Text::Table->new( $sep, '', $sep, '', $sep, '', $sep, '', $sep, '' ) | |||||||||||||||||||||||||||||||||
| 166 | ->load(@opts)->stringify . "\n"; | ||||||||||||||||||||||||||||||||||
| 167 | 6 | ▶ | if (keys %{$self->{subcmd}}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 1 | $help .= "Implemented commands are:\n"; | |||||||||||||||||||||||||||||||||
| 169 | 1 | $help .= " " . join(', ', sort keys %{$self->{subcmd}}) . "\n\n"; | |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 6 | $help; | |||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | 4 | ▶ | sub showHelp { | ||||||||||||||||||||||||||||||||
|
Subroutine
showHelp: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 177 | 4 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||
| 178 | 4 | ▶ | $fh //= *STDERR; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$fh //= *STDERR
MC/DC0%0/2
$fh //= *STDERR
$fh
*STDERR
Truth table33%1/3
A //= B
A= $fhB= *STDERR
| |||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | 4 | print $fh $self->help; | |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | 86 | ▶ | sub _set_v2a { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_v2a: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||
| 185 | 86 | my ($argv, $key, $value, $k) = @_; | |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | 86 | ▶ | if ($k) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | $argv->{$key} //= {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$argv->{$key} //= {}
MC/DC100%1/1
$argv->{$key} //= {}
$argv->{$key}
Truth table100%2/2
A
A= $argv->{$key}
| |||||||||||||||||||||||||||||||||||
| 189 | 5 | _set_v2a($argv->{$key}, $k, $value); | |||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||
| 191 | elsif (exists $argv->{$key}) { | ||||||||||||||||||||||||||||||||||
| 192 | 8 | ▶ | if (ref($argv->{$key})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 193 | 2 | push @{$argv->{$key}}, $value; | |||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||||||||
| 196 | 6 | $argv->{$key} = [ $argv->{$key}, $value ]; | |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||
| 200 | 73 | $argv->{$key} = $value; | |||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | 187 | ▶ | sub _get_real_name { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_real_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 205 | 187 | my ($self, $opt) = @_; | |||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 187 | ▶ | while (my $name = $self->{alias}->{$opt}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 208 | 12 | $opt = $name; | |||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||
| 210 | 187 | return $opt; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | sub _load_config { | ||||||||||||||||||||||||||||||||
|
Subroutine
_load_config: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||
| 214 | 3 | my ($self, $argv, $file) = @_; | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | # :raw reads the bytes as they are, with no decoding and no CRLF translation | ||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | open my $fh, '<:raw', $file or die "cannot open config file '$file': $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | 3 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||
| 219 | 3 | close $fh; | |||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 3 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||
| 222 | 14 | ▶ | next if $line =~ /^\[/; # section | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 10 | ▶ | next if $line =~ /^;/; # comment | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | next if $line !~ /=/; # bad format; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | 8 | chomp($line); | |||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | if ($line =~ /^(.+?[^\\])=(.*)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 228 | 8 | $argv->{$1} = $2; | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 69 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=67 SCAR=43.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 234 | 69 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 235 | 69 | ▶ | push @_, @ARGV unless @_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 69 | my $argv = {}; | |||||||||||||||||||||||||||||||||
| 238 | 69 | my @args; | |||||||||||||||||||||||||||||||||
| 239 | 69 | my $boolean = $self->{boolean}; | |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||
| 241 | 69 | my $key; | |||||||||||||||||||||||||||||||||
| 242 | my $nest_key; | ||||||||||||||||||||||||||||||||||
| 243 | 69 | my $stop = 0; | |||||||||||||||||||||||||||||||||
| 244 | 69 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||
| 245 | 153 | ▶ | if ($stop) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 246 | 20 | push @args, $arg; | |||||||||||||||||||||||||||||||||
| 247 | 20 | next; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | 133 | ▶ | if ($arg =~ /^--((?:\w|-|\.)+)=(.+)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 250 | 54 | my ($opt, $k) = split(/\./, $1); | |||||||||||||||||||||||||||||||||
| 251 | 54 | my $option = $self->_get_real_name($opt); | |||||||||||||||||||||||||||||||||
| 252 | 54 | ▶ | if ($k) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 253 | 4 | _set_v2a($argv, $option, $2, $k); | |||||||||||||||||||||||||||||||||
| 254 | } else { | ||||||||||||||||||||||||||||||||||
| 255 | 50 | _set_v2a($argv, $option, $2); | |||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | elsif ($arg =~ /^(-(\w)|--((?:\w|-|\.)+))$/) { | ||||||||||||||||||||||||||||||||||
| 259 | 38 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 260 | 2 | $argv->{$key} = 1; | |||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||
| 262 | 38 | ▶ | my $opt = $2 // $3; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$2 // $3
MC/DC100%2/2
$2 // $3
$2
$3
Truth table100%3/3
A // B
A= $2B= $3
| |||||||||||||||||||||||||||||||||||
| 263 | 38 | ▶ | if ($opt =~ /^no\-(.+)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 264 | 1 | my $option = $self->_get_real_name($1); | |||||||||||||||||||||||||||||||||
| 265 | 1 | $argv->{$option} = 0; | |||||||||||||||||||||||||||||||||
| 266 | 1 | next; | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | 37 | ($opt, my $k) = split(/\./, $opt); | |||||||||||||||||||||||||||||||||
| 269 | 37 | my $option = $self->_get_real_name($opt); | |||||||||||||||||||||||||||||||||
| 270 | 37 | ▶ | if ($boolean->{$option}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | if ($k) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $argv->{$option} //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$argv->{$option} //= {}
MC/DC0%0/1
$argv->{$option} //= {}
$argv->{$option}
Truth table0%0/2
A
A= $argv->{$option}
| |||||||||||||||||||||||||||||||||||
| 273 | 0 | $argv->{$option}->{$k} = 1; | |||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||
| 275 | 3 | $argv->{$option} = 1; | |||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||
| 279 | 34 | $key = $option; | |||||||||||||||||||||||||||||||||
| 280 | 34 | $nest_key = $k; | |||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | elsif ($arg =~ /^-(\w(?:\w|-|\.)+)$/) { | ||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 285 | 0 | $argv->{$key} = 1; | |||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||
| 287 | 2 | my $opt_str = $1; | |||||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | if ($opt_str =~ /^(.)([0-9])+$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | 1 | my $option = $self->_get_real_name($1); | |||||||||||||||||||||||||||||||||
| 290 | 1 | $argv->{$option} = $2; | |||||||||||||||||||||||||||||||||
| 291 | } else { | ||||||||||||||||||||||||||||||||||
| 292 | 1 | for (split //, $opt_str) { | |||||||||||||||||||||||||||||||||
| 293 | 3 | my $option = $self->_get_real_name($_); | |||||||||||||||||||||||||||||||||
| 294 | 3 | $argv->{$option} = 1; | |||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||
| 298 | elsif ($arg =~ /^--$/) { | ||||||||||||||||||||||||||||||||||
| 299 | # stop parsing | ||||||||||||||||||||||||||||||||||
| 300 | 4 | $stop = 1; | |||||||||||||||||||||||||||||||||
| 301 | 4 | next; | |||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||
| 303 | else { | ||||||||||||||||||||||||||||||||||
| 304 | 35 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 305 | 27 | ▶ | if ($nest_key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 306 | 1 | _set_v2a($argv, $key, $arg, $nest_key); | |||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||
| 308 | 26 | _set_v2a($argv, $key, $arg); | |||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||
| 310 | # reset | ||||||||||||||||||||||||||||||||||
| 311 | 27 | $key = $nest_key = undef; | |||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||
| 313 | else { | ||||||||||||||||||||||||||||||||||
| 314 | 8 | ▶ | if (!scalar(@args) && keys %{$self->{subcmd}}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not scalar @args and keys %{$$self{"subcmd"};}
MC/DC100%2/2
not scalar @args and keys %{$$self{"subcmd"};}
not scalar @args
keys %{$$self{"subcmd"};}
Truth table100%3/3
not(A) and B
A= not scalar @argsB= keys %{$$self{"subcmd"};}
| |||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | if ( $self->{subcmd}->{$arg} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 316 | 1 | $argv->{command} = $arg; | |||||||||||||||||||||||||||||||||
| 317 | 1 | $stop = 1; | |||||||||||||||||||||||||||||||||
| 318 | 1 | next; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||
| 321 | 0 | die "sub command '$arg' not defined."; | |||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | 7 | push @args, $arg; | |||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||
| 329 | 69 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 330 | 6 | ▶ | if ($nest_key) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $argv->{$key} //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$argv->{$key} //= {}
MC/DC0%0/1
$argv->{$key} //= {}
$argv->{$key}
Truth table0%0/2
A
A= $argv->{$key}
| |||||||||||||||||||||||||||||||||||
| 332 | 0 | $argv->{$key}->{$nest_key} = 1; | |||||||||||||||||||||||||||||||||
| 333 | } else { | ||||||||||||||||||||||||||||||||||
| 334 | 6 | $argv->{$key} = 1; | |||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | 69 | ▶ | if (my $parser = $self->{subcmd}->{$argv->{command}||''}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$argv->{'command'} || ''
MC/DC100%1/1
$argv->{'command'} || ''
$argv->{'command'}
Truth table100%2/2
A
A= $argv->{'command'}
| |||||||||||||||||||||||||||||||||||
| 339 | 1 | $argv->{cmd_option} = $parser->parse(@args); | |||||||||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||||||||
| 341 | 68 | $argv->{_} = \@args; | |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | 69 | for my $env (keys %{$self->{env}}) { | |||||||||||||||||||||||||||||||||
| 345 | 3 | ▶ | if (defined($ENV{uc($self->{env_prefix}."_$env")})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 346 | 2 | my $option = $self->_get_real_name($env); | |||||||||||||||||||||||||||||||||
| 347 | 2 | ▶ | $argv->{$option} //= $ENV{uc($self->{env_prefix}."_$env")}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$argv->{$option} //= $ENV{uc $self->{"env_prefix"} . "_$env"}
MC/DC0%0/2
$argv->{$option} //= $ENV{uc $self->{"env_prefix"} . "_$env"}
$argv->{$option}
$ENV{uc $self->{"env_prefix"} . "_$env"}
Truth table66%2/3
A //= B
A= $argv->{$option}B= $ENV{uc $self->{"env_prefix"} . "_$env"}
| |||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | 69 | ▶ | while (my ($key, $val) = each %{$self->{default}}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 352 | 7 | my $opt = $self->_get_real_name($key); | |||||||||||||||||||||||||||||||||
| 353 | 7 | ▶ | if (ref($val) && ref($val) eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $val and ref $val eq "CODE"
MC/DC50%1/2
ref $val and ref $val eq "CODE"
ref $val
ref $val eq "CODE"
Truth table66%2/3
A and B
A= ref $valB= ref $val eq "CODE"
| |||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | $argv->{$opt} //= $val->(); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$argv->{$opt} //= &$val()
MC/DC0%0/2
$argv->{$opt} //= &$val()
$argv->{$opt}
&$val()
Truth table33%1/3
A //= B
A= $argv->{$opt}B= &$val()
| |||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||
| 356 | else { | ||||||||||||||||||||||||||||||||||
| 357 | 6 | ▶ | $argv->{$opt} //= $val; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$argv->{$opt} //= $val
MC/DC0%0/2
$argv->{$opt} //= $val
$argv->{$opt}
$val
Truth table66%2/3
A //= B
A= $argv->{$opt}B= $val
| |||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | 69 | ▶ | while (my ($key, $val) = each %{$self->{type}}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 362 | 78 | ▶ | next if $val ne 'Config'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 363 | 31 | ▶ | next if !($argv->{$key}) || !(-f $argv->{$key}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$argv->{$key} and -f $argv->{$key}
MC/DC50%1/2
$argv->{$key} and -f $argv->{$key}
$argv->{$key}
-f $argv->{$key}
Truth table66%2/3
A and B
A= $argv->{$key}B= -f $argv->{$key}
| |||||||||||||||||||||||||||||||||||
| 364 | 3 | $self->_load_config($argv, delete $argv->{$key}); | |||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | 69 | for my $key (keys %{$self->{demand}}) { | |||||||||||||||||||||||||||||||||
| 368 | 8 | my $opt = $self->_get_real_name($key); | |||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | if (!$argv->{$opt}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 370 | 3 | $self->showHelp; | |||||||||||||||||||||||||||||||||
| 371 | 3 | print STDERR "\nMissing required arguments: $opt\n"; | |||||||||||||||||||||||||||||||||
| 372 | 3 | die; | |||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | 66 | for my $key (keys %{$self->{type}}) { | |||||||||||||||||||||||||||||||||
| 377 | 74 | my $opt = $self->_get_real_name($key); | |||||||||||||||||||||||||||||||||
| 378 | 74 | my $type = $self->{type}->{$key}; | |||||||||||||||||||||||||||||||||
| 379 | 74 | ▶ | if (my $c = $self->{coerce}->{$type}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 380 | 5 | $type = $c->{type}; | |||||||||||||||||||||||||||||||||
| 381 | 5 | $argv->{$opt} = $c->{generater}->($argv->{$opt}); | |||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||
| 383 | 74 | my $check = 0; | |||||||||||||||||||||||||||||||||
| 384 | 74 | ▶ | if ($type eq 'Bool') { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $argv->{$opt} //= 0; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$argv->{$opt} //= 0
MC/DC0%0/1
$argv->{$opt} //= 0
$argv->{$opt}
Truth table0%0/2
A
A= $argv->{$opt}
| |||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $check = ($argv->{$opt} =~ /^(0|1)$/) ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 387 | } elsif ($type eq 'Str') { | ||||||||||||||||||||||||||||||||||
| 388 | 3 | $check = 1; | |||||||||||||||||||||||||||||||||
| 389 | } elsif ($type eq 'Int') { | ||||||||||||||||||||||||||||||||||
| 390 | 19 | ▶ | if ($argv->{$opt}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 391 | 18 | ▶ | $check = ($argv->{$opt} =~ /^\-?\d+$/) ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 392 | } else { | ||||||||||||||||||||||||||||||||||
| 393 | 1 | $check = 1; | |||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||
| 395 | } elsif ($type eq 'Num') { | ||||||||||||||||||||||||||||||||||
| 396 | 10 | ▶ | if ($argv->{$opt}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 397 | 8 | ▶ | $check = ($argv->{$opt} =~ /^\-?\d+(\.\d+)?$/) ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 398 | } else { | ||||||||||||||||||||||||||||||||||
| 399 | 2 | $check = 1; | |||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||
| 401 | } elsif ($type eq 'ArrayRef') { | ||||||||||||||||||||||||||||||||||
| 402 | 10 | ▶ | $argv->{$opt} //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$argv->{$opt} //= []
MC/DC0%0/1
$argv->{$opt} //= []
$argv->{$opt}
Truth table50%1/2
A
A= $argv->{$opt}
| |||||||||||||||||||||||||||||||||||
| 403 | 10 | ▶ | unless (ref($argv->{$opt})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 404 | 2 | $argv->{$opt} = [$argv->{$opt}]; | |||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||
| 406 | 10 | ▶ | $check = (ref($argv->{$opt}) eq 'ARRAY') ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 407 | } elsif ($type eq 'HashRef') { | ||||||||||||||||||||||||||||||||||
| 408 | 2 | ▶ | $argv->{$opt} //= {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$argv->{$opt} //= {}
MC/DC0%0/1
$argv->{$opt} //= {}
$argv->{$opt}
Truth table50%1/2
A
A= $argv->{$opt}
| |||||||||||||||||||||||||||||||||||
| 409 | 2 | ▶ | $check = (ref($argv->{$opt}) eq 'HASH') ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 410 | } elsif ($type eq 'Config') { | ||||||||||||||||||||||||||||||||||
| 411 | 29 | ▶ | if ($argv->{$opt} && !(-f $argv->{$opt})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$argv->{$opt} and not -f $argv->{$opt}
MC/DC0%0/2
$argv->{$opt} and not -f $argv->{$opt}
$argv->{$opt}
not -f $argv->{$opt}
Truth table33%1/3
A and not(B)
A= $argv->{$opt}B= not -f $argv->{$opt}
| |||||||||||||||||||||||||||||||||||
| 412 | 0 | die "cannot load config file '@{[$argv->{$opt}]}\n"; | |||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||
| 414 | 29 | $check = 1; | |||||||||||||||||||||||||||||||||
| 415 | } else { | ||||||||||||||||||||||||||||||||||
| 416 | 1 | die "cannot find type constraint '$type'\n"; | |||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||
| 418 | 73 | ▶ | unless ($check) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 419 | 7 | die "Value '@{[$argv->{$opt}]}' invalid for option $opt($type)\n"; | |||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | 58 | ▶ | if ($argv->{help} && $self->{add_help}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$argv->{"help"} and $self->{"add_help"}
MC/DC50%1/2
$argv->{"help"} and $self->{"add_help"}
$argv->{"help"}
$self->{"add_help"}
Truth table66%2/3
A and B
A= $argv->{"help"}B= $self->{"add_help"}
| |||||||||||||||||||||||||||||||||||
| 424 | 1 | $self->showHelp; | |||||||||||||||||||||||||||||||||
| 425 | 1 | die; | |||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||
| 428 | 57 | $argv; | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | 21 | 1; | |||||||||||||||||||||||||||||||||
| 433 | __END__ | ||||||||||||||||||||||||||||||||||