| 1 | package MooX::ValidateSubs::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Type::Utils qw//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Type::Params qw/compile compile_named/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Types::Standard qw//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 76 | ▶ | sub _validate_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sub: called CC=33 SCAR=35.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 76 | my ( $self, $name, $type, $spec, @params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 76 | my $store_spec = sprintf '%s_spec', $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 76 | ▶ | my $compiled_check = ($self->$store_spec->{"compiled_$type"} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->$store_spec->{"compiled_$type"} ||= do {
if (ref $spec eq "ARRAY") {
my(@types) = map({() = (@$_, 0);
$default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;} @$spec);
compile(@types);
}
else {
my %types;
foreach my $key (keys %$spec) {
() = (@{$spec->{$key};}, 0);
$types{$key} = $default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;
};
compile_named(%types);
}
}
MC/DC0%0/2
$self->$store_spec->{"compiled_$type"} ||= do {
if (ref $spec eq "ARRAY") {
my(@types) = map({() = (@$_, 0);
$default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;} @$spec);
compile(@types);
}
else {
my %types;
foreach my $key (keys %$spec) {
() = (@{$spec->{$key};}, 0);
$types{$key} = $default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;
};
compile_named(%types);
}
}
$self->$store_spec->{"compiled_$type"}
do {
if (ref $spec eq "ARRAY") {
my(@types) = map({() = (@$_, 0);
$default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;} @$spec);
compile(@types);
}
else {
my %types;
foreach my $key (keys %$spec) {
() = (@{$spec->{$key};}, 0);
$types{$key} = $default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;
};
compile_named(%types);
}
}
Truth table66%2/3
A ||= B
A= $self->$store_spec->{"compiled_$type"}B= do {
if (ref $spec eq "ARRAY") {
my(@types) = map({() = (@$_, 0);
$default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;} @$spec);
compile(@types);
}
else {
my %types;
foreach my $key (keys %$spec) {
() = (@{$spec->{$key};}, 0);
$types{$key} = $default eq 1 ? &Types::Standard::Optional()->of($constraint) : $constraint;
};
compile_named(%types);
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | ▶ | if (ref $spec eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | my @types = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | my ($constraint, $default) = (@$_, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 33 | ▶ | $default eq '1' ? Types::Standard::Optional->of($constraint) : $constraint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } @$spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | compile(@types); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | my %types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 16 | for my $key (keys %$spec) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 56 | my ($constraint, $default) = (@{$spec->{$key}}, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 56 | ▶ | $types{$key} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $default eq '1' ? Types::Standard::Optional->of($constraint) : $constraint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | compile_named(%types); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 76 | my @count = ( scalar @params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 76 | ▶ | if ( ref $spec eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 36 | push @count, scalar @{$spec}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 36 | ▶ | @params = $self->_preprocess_params(@params) and $count[0] = scalar @params if ( do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
do {
my $preprocess = $count[0];
$_ == 0 || !$_ % 2 ? $params[$_] =~ /[0-9]+/ && $params[$_] <= $count[1] ? next : do {
$preprocess = 0
} && (last) : (next) foreach (0 .. $count[0] - 1);
$preprocess
} && ((@params = $self->_preprocess_params(@params)) && ($count[0] = scalar @params))
MC/DC0%0/2
do {
my $preprocess = $count[0];
$_ == 0 || !$_ % 2 ? $params[$_] =~ /[0-9]+/ && $params[$_] <= $count[1] ? next : do {
$preprocess = 0
} && (last) : (next) foreach (0 .. $count[0] - 1);
$preprocess
} && ((@params = $self->_preprocess_params(@params)) && ($count[0] = scalar @params))
do {
my $preprocess = $count[0];
$_ == 0 || !$_ % 2 ? $params[$_] =~ /[0-9]+/ && $params[$_] <= $count[1] ? next : do {
$preprocess = 0
} && (last) : (next) foreach (0 .. $count[0] - 1);
$preprocess
}
((@params = $self->_preprocess_params(@params)) && ($count[0] = scalar @params))
Truth table66%2/3
A && B
A= do {
my $preprocess = $count[0];
$_ == 0 || !$_ % 2 ? $params[$_] =~ /[0-9]+/ && $params[$_] <= $count[1] ? next : do {
$preprocess = 0
} && (last) : (next) foreach (0 .. $count[0] - 1);
$preprocess
}B= ((@params = $self->_preprocess_params(@params)) && ($count[0] = scalar @params))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 36 | my $preprocess = $count[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 36 | ▶ | $_ == 0 || ! $_ % 2 ? $params[$_] =~ m/[0-9]+/ && $params[$_] <= $count[1] ? next : do { $preprocess = 0 } && last : next foreach 0 .. $count[0] - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%6/8
$_ == 0 or !$_ % 2
$params[$_] =~ /[0-9]+/ and $params[$_] <= $count[1]
do {
$preprocess = 0
} and last
MC/DC50%1/2
$_ == 0 or !$_ % 2
$_ == 0
!$_ % 2
MC/DC100%2/2
$params[$_] =~ /[0-9]+/ and $params[$_] <= $count[1]
$params[$_] =~ /[0-9]+/
$params[$_] <= $count[1]
MC/DC0%0/1
do {
$preprocess = 0
} and last
do {
$preprocess = 0
}
Truth table66%2/3
A or not(B)
A= $_ == 0B= !$_ % 2
Truth table100%3/3
A and B
A= $params[$_] =~ /[0-9]+/B= $params[$_] <= $count[1]
Truth table50%1/2
A
A= do {
$preprocess = 0
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 36 | ▶ | $preprocess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
@params = $self->_preprocess_params(@params) and $count[0] = scalar @params
MC/DC0%0/2
@params = $self->_preprocess_params(@params) and $count[0] = scalar @params
@params = $self->_preprocess_params(@params)
$count[0] = scalar @params
Truth table33%1/3
A and B
A= @params = $self->_preprocess_params(@params)B= $count[0] = scalar @params
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 36 | ▶ | if ( $count[0] == 1 && $count[1] != 1 and ref $params[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$count[0] == 1 and $count[1] != 1 and ref $params[0] eq "ARRAY"
$count[0] == 1 and $count[1] != 1
MC/DC100%3/3
$count[0] == 1 and $count[1] != 1 and ref $params[0] eq "ARRAY"
$count[0] == 1
$count[1] != 1
ref $params[0] eq "ARRAY"
Truth table100%4/4
A and B and C
A= $count[0] == 1B= $count[1] != 1C= ref $params[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | @params = @{ $params[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | $count[0] = scalar @params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | $count[3] = 'ref'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 36 | $count[2] = $count[1] - grep { $spec->[$_]->[1] } 0 .. $count[1] - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 36 | ▶ | $count[0] >= $count[2] && $count[0] <= $count[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count[0] >= $count[2] and $count[0] <= $count[1]
MC/DC50%1/2
$count[0] >= $count[2] and $count[0] <= $count[1]
$count[0] >= $count[2]
$count[0] <= $count[1]
Truth table66%2/3
A and B
A= $count[0] >= $count[2]B= $count[0] <= $count[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | or croak sprintf 'Error - Invalid count in %s for sub - %s - expected - %s - got - %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $type, $name, $count[1], $count[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | foreach ( 0 .. $count[1] - 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 82 | ▶ | not $params[$_] and $spec->[$_]->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition63%7/11
!$params[$_] && $spec->[$_][1] && ($spec->[$_][1] =~ /^1$/ && (next) || ($params[$_] = $self->_default($spec->[$_][1])))
not $params[$_] and $spec->[$_][1]
$spec->[$_][1] =~ /^1$/ and next or $params[$_] = $self->_default($spec->[$_][1])
$spec->[$_][1] =~ /^1$/ and next
MC/DC0%0/4
!$params[$_] && $spec->[$_][1] && ($spec->[$_][1] =~ /^1$/ && (next) || ($params[$_] = $self->_default($spec->[$_][1])))
not $params[$_]
$spec->[$_][1]
$spec->[$_][1] =~ /^1$/
$params[$_] = $self->_default($spec->[$_][1])
Truth table20%1/5
not(A) and B && C or D
A= not $params[$_]B= $spec->[$_][1]C= $spec->[$_][1] =~ /^1$/D= $params[$_] = $self->_default($spec->[$_][1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | and ( $spec->[$_]->[1] =~ m/^1$/ and next or $params[$_] = $self->_default( $spec->[$_]->[1] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 29 | @params = $compiled_check->(@params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 29 | ▶ | return defined $count[3] ? \@params : @params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 40 | ▶ | my %para = $count[0] == 1 ? %{ $params[0] } : @params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 40 | my %cry = ( %{$spec}, %para ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 40 | foreach ( keys %cry ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | not $para{$_} and $spec->{$_}->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 139 | ▶ | and ( $spec->{$_}->[1] =~ m/^1$/ and next or $para{$_} = $self->_default( $spec->{$_}->[1] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition72%8/11
!$para{$_} && $spec->{$_}[1] && ($spec->{$_}[1] =~ /^1$/ && (next) || ($para{$_} = $self->_default($spec->{$_}[1])))
not $para{$_} and $spec->{$_}[1]
$spec->{$_}[1] =~ /^1$/ and next or $para{$_} = $self->_default($spec->{$_}[1])
$spec->{$_}[1] =~ /^1$/ and next
MC/DC0%0/4
!$para{$_} && $spec->{$_}[1] && ($spec->{$_}[1] =~ /^1$/ && (next) || ($para{$_} = $self->_default($spec->{$_}[1])))
not $para{$_}
$spec->{$_}[1]
$spec->{$_}[1] =~ /^1$/
$para{$_} = $self->_default($spec->{$_}[1])
Truth table40%2/5
not(A) and B && C or D
A= not $para{$_}B= $spec->{$_}[1]C= $spec->{$_}[1] =~ /^1$/D= $para{$_} = $self->_default($spec->{$_}[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 40 | my $paraRef = $compiled_check->(\%para); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 28 | ▶ | return $count[0] == 1 ? $paraRef : %{$paraRef}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 80 | ▶ | sub _default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 80 | my ( $self, $default ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 80 | ▶ | if ( ref $default eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 62 | return $default->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 18 | return $self->$default; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | ▶ | sub _preprocess_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_preprocess_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | my @world; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | map { $world[$_] = $params{$_} } sort keys %params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | return @world; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||