JSV/Keyword/Draft4/OneOf.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/AnyOf.pm ↑ Summary JSV/Keyword/Draft4/Maximum.pm »
1 package JSV::Keyword::Draft4::OneOf;
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() { "oneOf" }
11 sub keyword_priority() { 10; }
12  
13 20 ▶sub validate {
Subroutine validate: called CC=5 SCAR=16.1
Pod undocumented
14 20 my ($class, $context, $schema, $instance) = @_;
15  
16 20 my $one_of = $class->keyword_value($schema);
17 20 my $valid_cnt = 0;
18  
19 20 ▶ if (scalar(@$one_of) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$one_of == 1) 1 19 20
20 1 my $sub_schema = $one_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 19 ▶ for (my $i = 0, my $l = scalar(@$one_of); $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 38 19 57
28 38 my $sub_schema = $one_of->[$i];
29 local $context->{current_schema_pointer} =
30 38 $context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i;
31 38 local $context->{errors} = [];
32 38 $context->validate($sub_schema, $instance);
33 38 ▶ $valid_cnt += 1 unless scalar @{ $context->{errors} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$context->{"errors"};} 19 19 38
34 }
35  
36 19 ▶ unless ($valid_cnt == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid_cnt == 1) 10 9 19
37 10 $context->log_error("The instance is not matched to one of schemas");
38 }
39 }
40  
41 47 1;
« JSV/Keyword/Draft4/AnyOf.pm ↑ Summary JSV/Keyword/Draft4/Maximum.pm »