JSV/Keyword/Draft4/Properties.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 12 / 12 Conditioncond 90.0% 9 / 10 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 95.2% 81 / 85 CC 13 SCAR 22.2
CC
13
Cov
99%
validate
13.0
BEGIN
1.0
BEGIN
1.0
CRAP 9.2
« JSV/Context.pm ↑ Summary JSV/Reference.pm »
1 package JSV::Keyword::Draft4::Properties;
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 47 ▶use JSV::Util::Type qw(detect_instance_type escape_json_pointer);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub instance_type() { INSTANCE_TYPE_OBJECT(); }
11 sub keyword() { 'properties' }
12 328 ▶sub additional_keywords() { [qw/additionalProperties patternProperties/]; }
Subroutine additional_keywords: called CC=1 SCAR=0.0
Pod undocumented
13 sub keyword_priority() { 10; }
14  
15 226 ▶sub validate {
Subroutine validate: called CC=13 SCAR=25.7
Pod undocumented
16 226 my ($class, $context, $schema, $instance) = @_;
17  
18 226 ▶ my $properties = $class->keyword_value($schema) || {};
Condition100%2/2
$class->keyword_value($schema) || {}
l!l
21511
MC/DC100%1/1
$class->keyword_value($schema) || {}
$class->keyword_value($schema)
Truth table100%2/2
A
A= $class->keyword_value($schema)
Aresult
11
00
19 226 ▶ my $pattern_properties = $class->keyword_value($schema, "patternProperties") || {};
Condition100%2/2
$class->keyword_value($schema, 'patternProperties') || {}
l!l
33193
MC/DC100%1/1
$class->keyword_value($schema, 'patternProperties') || {}
$class->keyword_value($schema, 'patternProperties')
Truth table100%2/2
A
A= $class->keyword_value($schema, 'patternProperties')
Aresult
11
00
20  
21 226 my @patterns = ();
22 226 my @pattern_schemas = ();
23 226 my @original_patterns = ();
24 226 for my $pattern (keys %$pattern_properties) {
25 49 push(@patterns, qr/$pattern/);
26 49 push(@pattern_schemas, $pattern_properties->{$pattern});
27 49 push(@original_patterns, $pattern);
28 }
29  
30 226 my $additional_properties = $class->keyword_value($schema, "additionalProperties");
31 226 my $additional_properties_type = detect_instance_type($schema->{additionalProperties});
32 226 my %s = map { $_ => undef } keys %$instance;
33  
34 226 for my $property (keys %$instance) {
35 403 local $context->{current_pointer} = $context->{current_pointer} . "/" . escape_json_pointer( $property );
36  
37 403 ▶ if (exists $properties->{$property}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $properties->{$property}) 283 120 403
38 local $context->{current_schema_pointer} =
39 283 $context->{current_schema_pointer} . "/properties/" . escape_json_pointer( $property );
40 283 $context->validate($properties->{$property}, $instance->{$property});
41 283 delete $s{$property};
42 }
43  
44 403 ▶ for (my $i = 0, my $l = scalar(@patterns); $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 49 403 452
45 49 ▶ next unless ($property =~ m/$patterns[$i]/);
Branch: 1 branch
BranchTrueFalseTotal
unless $property =~ /$patterns[$i]/ 30 19 49
46 local $context->{current_schema_pointer} =
47 19 $context->{current_schema_pointer} . "/patternProperties/" . escape_json_pointer( $original_patterns[$i] );
48 19 $context->validate($pattern_schemas[$i], $instance->{$property});
49 19 delete $s{$property};
50 }
51  
52 403 ▶ if (exists $s{$property} && $additional_properties_type eq "object") {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s{$property} and $additional_properties_type eq "object") 13 390 403
Condition100%3/3
exists $s{$property} and $additional_properties_type eq "object"
!ll&&!rl&&r
2969413
MC/DC100%2/2
exists $s{$property} and $additional_properties_type eq "object"
exists $s{$property} $additional_properties_type eq "object"
Truth table100%3/3
A and B
A= exists $s{$property}B= $additional_properties_type eq "object"
ABresult
0X0
100
111
53 local $context->{current_schema_pointer} =
54 13 $context->{current_schema_pointer} . "/additionalProperties";
55 13 $context->validate($additional_properties, $instance->{$property});
56 }
57 }
58  
59 226 ▶ if ($additional_properties_type eq "boolean" && !$additional_properties) {
Branch: 1 branch
BranchTrueFalseTotal
if ($additional_properties_type eq "boolean" and not $additional_properties) 16 210 226
Condition66%2/3
$additional_properties_type eq "boolean" and not $additional_properties
!ll&&!rl&&r
210016
MC/DC50%1/2
$additional_properties_type eq "boolean" and not $additional_properties
$additional_properties_type eq "boolean" not $additional_properties
Truth table66%2/3
A and not(B)
A= $additional_properties_type eq "boolean"B= not $additional_properties
ABresult
0X0
100
111
60 16 ▶ if (keys %s > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %s > 0) 6 10 16
61 # TODO: provide pointer for each extra property
62 # (to avoid parsing error message and don't depend on its format)
63 6 $context->log_error(sprintf("Not allowed properties exist (properties: %s)", join(", ", keys %s)));
64 }
65 }
66 }
67  
68 47 1;
« JSV/Context.pm ↑ Summary JSV/Reference.pm »