Valiemon/Attributes/Required.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 96.7% 60 / 62 CC 7 SCAR 8.1
CC
7
Cov
100%
__ANON__
4.0
__ANON__
3.0
is_valid
2.0
CRAP 2.2
« Valiemon/Attributes/AdditionalItems.pm ↑ Summary Valiemon/Attributes/MaxProperties.pm »
1 package Valiemon::Attributes::Required;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use parent qw(Valiemon::Attributes);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use List::MoreUtils qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 68 ▶sub attr_name { 'required' }
Subroutine attr_name: called CC=1 SCAR=0.0
Pod undocumented
11  
12 80 ▶sub is_valid {
Subroutine is_valid: called CC=2 SCAR=6.9
Pod undocumented
13 80 my ($class, $context, $schema, $data) = @_;
14  
15 80 ▶ return 1 unless ref $data eq 'HASH'; # ignore
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 12 68 80
16  
17 68 my $required = $schema->{required};
18 68 ▶ $context->in_attr($class, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
19 68 ▶ if (ref $required ne 'ARRAY' || scalar @$required < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $required ne "ARRAY" or scalar @$required < 1) 2 66 68
Condition100%3/3
ref $required ne "ARRAY" or scalar @$required < 1
l!l&&r!l&&!r
1166
MC/DC100%2/2
ref $required ne "ARRAY" or scalar @$required < 1
ref $required ne "ARRAY" scalar @$required < 1
Truth table100%3/3
A or B
A= ref $required ne "ARRAY"B= scalar @$required < 1
ABresult
1X1
011
000
20 2 croak sprintf '`required` must be an array and have at leas one element at %s', $context->position
21 }
22 86 ▶ all {
Subroutine __ANON__: called CC=4 SCAR=13.9
23 86 my $prop_def = $schema->{properties}->{$_};
24 86 ▶ my $has_default = $prop_def && do {
Condition100%3/3
$prop_def && do { my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; $definition->{'default'} }
!ll&&!rl&&r
11714
MC/DC100%2/2
$prop_def && do { my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; $definition->{'default'} }
$prop_def do { my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; $definition->{'default'} }
Truth table100%3/3
A && B
A= $prop_defB= do { my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; $definition->{'default'} }
ABresult
0X0
100
111
25 # resolve $ref TODO refactor
26 75 ▶ my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
Branch: 1 branch
BranchTrueFalseTotal
$prop_def->{'$ref'} ? : 5 70 75
27 75 $definition->{default};
28 };
29 86 ▶ $has_default || exists $data->{$_}
Branch: 1 branch
BranchTrueFalseTotal
$has_default or exists $data->{$_} 4 82 86
30 66 } @$required;
31 68 });
32 }
33  
34 10 1;
« Valiemon/Attributes/AdditionalItems.pm ↑ Summary Valiemon/Attributes/MaxProperties.pm »