blib/lib/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
« blib/lib/Valiemon/Attributes/AdditionalItems.pm ↑ Summary blib/lib/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 66 ▶sub attr_name { 'required' }
Subroutine attr_name: called CC=1 SCAR=0.0
Pod undocumented
11  
12 sub is_valid {
13 78 ▶ my ($class, $context, $schema, $data) = @_;
Subroutine is_valid: called CC=2 SCAR=6.9
Pod undocumented
14  
15 78 ▶ return 1 unless ref $data eq 'HASH'; # ignore
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 12 66 78
16  
17 66 my $required = $schema->{required};
18 $context->in_attr($class, sub {
19 66 ▶ if (ref $required ne 'ARRAY' || scalar @$required < 1) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if (ref $required ne "ARRAY" or scalar @$required < 1) 2 64 66
Condition100%3/3
ref $required ne "ARRAY" or scalar @$required < 1
l!l&&r!l&&!r
1164
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 all {
23 84 ▶ my $prop_def = $schema->{properties}->{$_};
Subroutine __ANON__: called CC=4 SCAR=13.9
24 84 ▶ 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
11694
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 73 ▶ my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
Branch: 1 branch
BranchTrueFalseTotal
$prop_def->{'$ref'} ? : 5 68 73
27 73 $definition->{default};
28 };
29 84 ▶ $has_default || exists $data->{$_}
Branch: 1 branch
BranchTrueFalseTotal
$has_default or exists $data->{$_} 80 4 84
30 64 } @$required;
31 66 });
32 }
33  
34 10 1;
« blib/lib/Valiemon/Attributes/AdditionalItems.pm ↑ Summary blib/lib/Valiemon/Attributes/MaxProperties.pm »