line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Items; |
2
|
|
|
|
|
|
|
|
3
|
47
|
|
|
47
|
|
21575
|
use strict; |
|
47
|
|
|
|
|
55
|
|
|
47
|
|
|
|
|
1104
|
|
4
|
47
|
|
|
47
|
|
2525
|
use warnings; |
|
47
|
|
|
|
|
70
|
|
|
47
|
|
|
|
|
1175
|
|
5
|
47
|
|
|
47
|
|
159
|
use parent qw(JSV::Keyword); |
|
47
|
|
|
|
|
47
|
|
|
47
|
|
|
|
|
158
|
|
6
|
|
|
|
|
|
|
|
7
|
47
|
|
|
47
|
|
1861
|
use JSON; |
|
47
|
|
|
|
|
58
|
|
|
47
|
|
|
|
|
159
|
|
8
|
|
|
|
|
|
|
|
9
|
47
|
|
|
47
|
|
3596
|
use JSV::Keyword qw(:constants); |
|
47
|
|
|
|
|
61
|
|
|
47
|
|
|
|
|
3988
|
|
10
|
47
|
|
|
47
|
|
190
|
use JSV::Util::Type qw(detect_instance_type escape_json_pointer); |
|
47
|
|
|
|
|
50
|
|
|
47
|
|
|
|
|
14571
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub instance_type() { INSTANCE_TYPE_ARRAY(); } |
13
|
|
|
|
|
|
|
sub keyword() { "items" } |
14
|
|
|
|
|
|
|
sub keyword_priority() { 10; } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub validate { |
17
|
57
|
|
|
57
|
0
|
53
|
my ($class, $context, $schema, $instance) = @_; |
18
|
|
|
|
|
|
|
|
19
|
57
|
|
|
|
|
120
|
my $items = $class->keyword_value($schema); |
20
|
57
|
|
|
|
|
111
|
my $additional_items = $class->keyword_value($schema, "additionalItems"); |
21
|
|
|
|
|
|
|
|
22
|
57
|
|
|
|
|
96
|
my $items_type = detect_instance_type($items); |
23
|
57
|
|
|
|
|
84
|
my $additional_items_type = detect_instance_type($additional_items); |
24
|
|
|
|
|
|
|
|
25
|
57
|
100
|
|
|
|
111
|
if ($items_type eq "object") { ### items as schema |
|
|
50
|
|
|
|
|
|
26
|
21
|
|
|
|
|
63
|
local $context->{current_schema_pointer} = $context->{current_schema_pointer} . "/" . $class->keyword; |
27
|
21
|
|
|
|
|
60
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
28
|
49
|
|
|
|
|
86
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
29
|
49
|
|
|
|
|
108
|
$context->validate($items, $instance->[$i]); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ($items_type eq "array") { ### items as schema array |
33
|
36
|
|
|
|
|
83
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
34
|
112
|
|
|
|
|
209
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
35
|
|
|
|
|
|
|
|
36
|
112
|
100
|
66
|
|
|
211
|
if (defined $items->[$i]) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
37
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
38
|
89
|
|
|
|
|
192
|
$context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i; |
39
|
89
|
|
|
|
|
152
|
$context->validate($items->[$i], $instance->[$i]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($additional_items_type eq "object") { |
42
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
43
|
13
|
|
|
|
|
20
|
$context->{current_schema_pointer} . "/additionalItems"; |
44
|
13
|
|
|
|
|
23
|
$context->validate($additional_items, $instance->[$i]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($additional_items_type eq "boolean" && $additional_items == JSON::false) { |
47
|
4
|
|
|
|
|
41
|
$context->log_error("additionalItems are not allowed"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { ### wrong schema |
52
|
0
|
|
|
|
|
|
$context->log_error("Wrong schema definition"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |