JSV/Keyword/Draft4/AnyOf.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 97.7% 43 / 44 CC 5 SCAR 11.7
CC
5
Cov
100%
validate
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« JSV/Keyword/Draft4/Dependencies.pm ↑ Summary JSV/Keyword/Draft4/OneOf.pm »
1 package JSV::Keyword::Draft4::AnyOf;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 ▶use parent qw(JSV::Keyword);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 ▶use JSV::Keyword qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub instance_type() { INSTANCE_TYPE_ANY(); }
10 sub keyword() { "anyOf" }
11 sub keyword_priority() { 10; }
12  
13 22 ▶sub validate {
Subroutine validate: called CC=5 SCAR=16.1
Pod undocumented
14 22 my ($class, $context, $schema, $instance) = @_;
15  
16 22 my $any_of = $class->keyword_value($schema);
17 22 my $valid_cnt = 0;
18  
19 22 ▶ if (scalar(@$any_of) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$any_of == 1) 1 21 22
20 1 my $sub_schema = $any_of->[0];
21 local $context->{current_schema_pointer} =
22 1 $context->{current_schema_pointer} . "/" . $class->keyword . "/0";
23 1 $context->validate($sub_schema, $instance);
24 1 return;
25 }
26  
27 21 ▶ for (my $i = 0, my $l = scalar(@$any_of); $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 42 21 63
28 42 my $sub_schema = $any_of->[$i];
29 local $context->{current_schema_pointer} =
30 42 $context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i;
31 42 local $context->{errors} = [];
32 42 $context->validate($sub_schema, $instance);
33 42 ▶ $valid_cnt += 1 unless scalar @{ $context->{errors} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$context->{"errors"};} 18 24 42
34 }
35  
36 21 ▶ if ($valid_cnt == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid_cnt == 0) 7 14 21
37 7 $context->log_error("The instance is not valid to any of schemas");
38 }
39 }
40  
41 47 1;
« JSV/Keyword/Draft4/Dependencies.pm ↑ Summary JSV/Keyword/Draft4/OneOf.pm »