| 1 | # ABSTRACT: Processes and validates options and parameters | ||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | package App::Spec::Run::Validator; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 6 | our $VERSION = 'v0.15.1'; # TRIAL VERSION; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use List::Util qw/ any /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use List::MoreUtils qw/ uniq /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Ref::Util qw/ is_arrayref is_hashref /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 6 | has options => ( is => 'ro' ); | |||||||||||||||||||||||||||||||
| 14 | 6 | has option_specs => ( is => 'ro' ); | |||||||||||||||||||||||||||||||
| 15 | 6 | has parameters => ( is => 'ro' ); | |||||||||||||||||||||||||||||||
| 16 | 6 | has param_specs => ( is => 'ro' ); | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | my %validate = ( | ||||||||||||||||||||||||||||||||
| 19 | 36 | ▶ | string => sub { length($_[0]) > 0 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | file => sub { $_[0] eq '-' or -f $_[0] }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | filename => sub { 1 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | dir => sub { -d $_[0] }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | dirname => sub { 1 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | integer => sub { $_[0] =~ m/^[+-]?\d+$/ }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | float => sub { $_[0] =~ m/^[+-]?\d+(?:\.\d+)?$/ }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | flag => sub { 1 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | enum => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 7 | my ($value, $list) = @_; | |||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | any { $value eq $_ } @$list; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||
| 31 | 6 | ); | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 31 | ▶ | sub process { | ||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 34 | 31 | my ($self, $run, $errs) = @_; | |||||||||||||||||||||||||||||||
| 35 | 31 | my ($ok) = $self->_process( $errs, type => "parameters", app => $run ); | |||||||||||||||||||||||||||||||
| 36 | 31 | ▶ | $ok &&= $self->_process( $errs, type => "options", app => $run ); | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$ok &&= $self->_process($errs, "type", "options", "app", $run)
MC/DC100%2/2
$ok &&= $self->_process($errs, "type", "options", "app", $run)
$ok
$self->_process($errs, "type", "options", "app", $run)
Truth table100%3/3
A &&= B
A= $okB= $self->_process($errs, "type", "options", "app", $run)
| |||||||||||||||||||||||||||||||||
| 37 | 31 | return $ok; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 51 | ▶ | sub _process { | ||||||||||||||||||||||||||||||
|
Subroutine
_process: called CC=55 SCAR=44.5
| |||||||||||||||||||||||||||||||||
| 41 | 51 | my ($self, $errs, %args) = @_; | |||||||||||||||||||||||||||||||
| 42 | 51 | my $run = $args{app}; | |||||||||||||||||||||||||||||||
| 43 | 51 | my $type = $args{type}; | |||||||||||||||||||||||||||||||
| 44 | 51 | my ($items, $specs); | |||||||||||||||||||||||||||||||
| 45 | 51 | ▶ | if ($args{type} eq "parameters") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 31 | $items = $self->parameters; | |||||||||||||||||||||||||||||||
| 47 | 31 | $specs = $self->param_specs; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||||||
| 50 | 20 | $items = $self->options; | |||||||||||||||||||||||||||||||
| 51 | 20 | $specs = $self->option_specs; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # TODO: iterate over parameters in original cmdline order | ||||||||||||||||||||||||||||||||
| 55 | 51 | for my $name (sort keys %$specs) { | |||||||||||||||||||||||||||||||
| 56 | 136 | my $spec = $specs->{ $name }; | |||||||||||||||||||||||||||||||
| 57 | 136 | my $value = $items->{ $name }; | |||||||||||||||||||||||||||||||
| 58 | 136 | my $param_type = $spec->type; | |||||||||||||||||||||||||||||||
| 59 | 136 | my $enum = $spec->enum; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 136 | ▶ | if ($spec->type eq "flag") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 52 | ▶ | if ($spec->multiple) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 17 | ▶ | if (defined $value and $value !~ m/^\d+$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and not $value =~ /^\d+$/
MC/DC0%0/2
defined $value and not $value =~ /^\d+$/
defined $value
not $value =~ /^\d+$/
Truth table66%2/3
A and not(B)
A= defined $valueB= not $value =~ /^\d+$/
| |||||||||||||||||||||||||||||||||
| 64 | 0 | die "Value for '$name': '$value' shouldn't happen"; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||
| 68 | 35 | ▶ | if (defined $value and $value != 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and $value != 1
MC/DC0%0/2
defined $value and $value != 1
defined $value
$value != 1
Truth table66%2/3
A and B
A= defined $valueB= $value != 1
| |||||||||||||||||||||||||||||||||
| 69 | 0 | die "Value for '$name': '$value' shouldn't happen"; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | 52 | next; | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 84 | my $values; | |||||||||||||||||||||||||||||||
| 76 | 84 | ▶ | if ($spec->multiple and $spec->mapping) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$spec->multiple and $spec->mapping
MC/DC100%2/2
$spec->multiple and $spec->mapping
$spec->multiple
$spec->mapping
Truth table100%3/3
A and B
A= $spec->multipleB= $spec->mapping
| |||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | if (not defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | $items->{ $name } = $value = {}; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | 5 | $values = $value; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | if (not keys %$values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (defined (my $default = $spec->default)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | $values = { split m/=/, $default, 2 }; | |||||||||||||||||||||||||||||||
| 85 | 0 | $items->{ $name } = $values; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | if (not keys %$values and $spec->required) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not keys %$values and $spec->required
MC/DC0%0/2
not keys %$values and $spec->required
not keys %$values
$spec->required
Truth table33%1/3
not(A) and B
A= not keys %$valuesB= $spec->required
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $errs->{ $type }->{ $name } = "missing"; | |||||||||||||||||||||||||||||||
| 91 | 0 | next; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | if (not keys %$values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | 0 | next; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | elsif ($spec->multiple) { | ||||||||||||||||||||||||||||||||
| 100 | 11 | ▶ | if (not defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 0 | $items->{ $name } = $value = []; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | 11 | $values = $value; | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 11 | ▶ | if (not @$values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | if (defined (my $default = $spec->default)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 0 | $values = [ $default ]; | |||||||||||||||||||||||||||||||
| 108 | 0 | $items->{ $name } = $values; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 11 | ▶ | if ( not @$values and $spec->required) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @$values and $spec->required
MC/DC50%1/2
not @$values and $spec->required
not @$values
$spec->required
Truth table66%2/3
not(A) and B
A= not @$valuesB= $spec->required
| |||||||||||||||||||||||||||||||||
| 113 | 6 | $errs->{ $type }->{ $name } = "missing"; | |||||||||||||||||||||||||||||||
| 114 | 6 | next; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | if (not @$values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 0 | next; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 5 | ▶ | if ($spec->unique and (uniq @$values) != @$values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->unique and &uniq(@$values) != @$values
MC/DC50%1/2
$spec->unique and &uniq(@$values) != @$values
$spec->unique
&uniq(@$values) != @$values
Truth table66%2/3
A and B
A= $spec->uniqueB= &uniq(@$values) != @$values
| |||||||||||||||||||||||||||||||||
| 122 | 1 | $errs->{ $type }->{ $name } = "not_unique"; | |||||||||||||||||||||||||||||||
| 123 | 1 | next; | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 68 | ▶ | if (not defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 38 | ▶ | if (defined (my $default = $spec->default)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | 0 | $value = $default; | |||||||||||||||||||||||||||||||
| 132 | 0 | $items->{ $name } = $value; | |||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 68 | ▶ | if ( not defined $value and $spec->required) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value and $spec->required
MC/DC100%2/2
not defined $value and $spec->required
not defined $value
$spec->required
Truth table100%3/3
not(A) and B
A= not defined $valueB= $spec->required
| |||||||||||||||||||||||||||||||||
| 137 | 4 | $errs->{ $type }->{ $name } = "missing"; | |||||||||||||||||||||||||||||||
| 138 | 4 | next; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 64 | ▶ | if (not defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | 34 | next; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 30 | $values = [ $value ]; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 39 | my $def; | |||||||||||||||||||||||||||||||
| 149 | 39 | ▶ | if (ref $param_type eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 0 | ($param_type, $def) = %$param_type; | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | 39 | ▶ | my $code = $validate{ $param_type } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | or die "Missing method for validation type $param_type"; | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 39 | ▶ | my $possible_values = $spec->mapping ? {} : []; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | 39 | ▶ | if (my $spec_values = $spec->values) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | 25 | ▶ | if (my $op = $spec_values->{op}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 158 | 20 | my $args = { | |||||||||||||||||||||||||||||||
| 159 | runmode => "validation", | ||||||||||||||||||||||||||||||||
| 160 | parameter => $name, | ||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||
| 162 | 20 | ▶ | $possible_values = $run->cmd->$op($run, $args) || []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$run->cmd->$op($run, $args) || []
MC/DC100%1/1
$run->cmd->$op($run, $args) || []
$run->cmd->$op($run, $args)
Truth table100%2/2
A
A= $run->cmd->$op($run, $args)
| |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | elsif ($spec->mapping) { | ||||||||||||||||||||||||||||||||
| 165 | 5 | $possible_values = $spec_values->{mapping}; | |||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | else { | ||||||||||||||||||||||||||||||||
| 168 | 0 | $possible_values = $values->{enum}; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | my @to_check = $spec->mapping | ||||||||||||||||||||||||||||||||
| 173 | 39 | ▶ | ? map { [ $_ => $values->{ $_ } ] } keys %$values | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | : @$values; | ||||||||||||||||||||||||||||||||
| 175 | 39 | for my $item (@to_check) { | |||||||||||||||||||||||||||||||
| 176 | 42 | my ($key, $v); | |||||||||||||||||||||||||||||||
| 177 | 42 | ▶ | if ($spec->mapping) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 178 | 6 | ($key, $v) = @$item; | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||
| 181 | 36 | $v = $item; | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | # check type validity | ||||||||||||||||||||||||||||||||
| 184 | 42 | my $ok = $code->($v, $def); | |||||||||||||||||||||||||||||||
| 185 | 42 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | 4 | $errs->{ $type }->{ $name } = "invalid $param_type"; | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | # check static enums | ||||||||||||||||||||||||||||||||
| 189 | 42 | ▶ | if ($enum) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 190 | my $code = $validate{enum} | ||||||||||||||||||||||||||||||||
| 191 | 7 | ▶ | or die "Missing method for validation type enum"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 192 | 7 | my $ok = $code->($v, $enum); | |||||||||||||||||||||||||||||||
| 193 | 7 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 1 | $errs->{ $type }->{ $name } = "invalid enum"; | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | 42 | ▶ | if ($param_type eq 'file' and $v eq '-') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param_type eq "file" and $v eq "-"
MC/DC0%0/2
$param_type eq "file" and $v eq "-"
$param_type eq "file"
$v eq "-"
Truth table33%1/3
A and B
A= $param_type eq "file"B= $v eq "-"
| |||||||||||||||||||||||||||||||||
| 198 | 0 | $v = do { local $/; my $t = <STDIN>; \$t }; | |||||||||||||||||||||||||||||||
| 199 | # TODO does not work for multiple | ||||||||||||||||||||||||||||||||
| 200 | 0 | $items->{ $name } = $v; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 42 | ▶ | if ($spec->mapping and keys %$possible_values) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$spec->mapping and keys %$possible_values
MC/DC50%1/2
$spec->mapping and keys %$possible_values
$spec->mapping
keys %$possible_values
Truth table66%2/3
A and B
A= $spec->mappingB= keys %$possible_values
| |||||||||||||||||||||||||||||||||
| 204 | 6 | my $ok = 0; | |||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | if (exists $possible_values->{ $key }) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | 3 | ▶ | if (my $list = $possible_values->{ $key }) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 207 | 2 | ▶ | $ok = any { $_ eq $v } @$list; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | else { | ||||||||||||||||||||||||||||||||
| 210 | # can have any value | ||||||||||||||||||||||||||||||||
| 211 | 1 | $ok = 1; | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | 6 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | 3 | $errs->{ $type }->{ $name } = "invalid value"; | |||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | elsif (@$possible_values) { | ||||||||||||||||||||||||||||||||
| 219 | 35 | ▶ | my $ok = any { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 220 | 35 | ▶ | is_hashref($_) ? $_->{name} eq $v : $_ eq $v | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 221 | 19 | } @$possible_values; | |||||||||||||||||||||||||||||||
| 222 | 19 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | 3 | $errs->{ $type }->{ $name } = "invalid value"; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | 51 | ▶ | return (keys %$errs) ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 6 | 1; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | __END__ | ||||||||||||||||||||||||||||||||