| 1 | package JSV::Keyword::Draft4::Items; | ||||||||||||||||||||
| 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 JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 47 | ▶ | use JSV::Keyword qw(:constants); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 47 | ▶ | use JSV::Util::Type qw(detect_instance_type escape_json_pointer); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub instance_type() { INSTANCE_TYPE_ARRAY(); } | ||||||||||||||||||||
| 13 | sub keyword() { "items" } | ||||||||||||||||||||
| 14 | sub keyword_priority() { 10; } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 57 | ▶ | sub validate { | ||||||||||||||||||
|
Subroutine
validate: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||
| 17 | 57 | my ($class, $context, $schema, $instance) = @_; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 57 | my $items = $class->keyword_value($schema); | |||||||||||||||||||
| 20 | 57 | my $additional_items = $class->keyword_value($schema, "additionalItems"); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 57 | my $items_type = detect_instance_type($items); | |||||||||||||||||||
| 23 | 57 | my $additional_items_type = detect_instance_type($additional_items); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 57 | ▶ | if ($items_type eq "object") { ### items as schema | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 26 | 21 | local $context->{current_schema_pointer} = $context->{current_schema_pointer} . "/" . $class->keyword; | |||||||||||||||||||
| 27 | 21 | ▶ | for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 49 | local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; | |||||||||||||||||||
| 29 | 49 | $context->validate($items, $instance->[$i]); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | elsif ($items_type eq "array") { ### items as schema array | ||||||||||||||||||||
| 33 | 36 | ▶ | for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 112 | local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 112 | ▶ | if (defined $items->[$i]) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 37 | local $context->{current_schema_pointer} = | ||||||||||||||||||||
| 38 | 89 | $context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i; | |||||||||||||||||||
| 39 | 89 | $context->validate($items->[$i], $instance->[$i]); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | elsif ($additional_items_type eq "object") { | ||||||||||||||||||||
| 42 | local $context->{current_schema_pointer} = | ||||||||||||||||||||
| 43 | 13 | $context->{current_schema_pointer} . "/additionalItems"; | |||||||||||||||||||
| 44 | 13 | $context->validate($additional_items, $instance->[$i]); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | ▶ | elsif ($additional_items_type eq "boolean" && $additional_items == JSON::false) { | |||||||||||||||||||
|
Condition66%2/3
$additional_items_type eq "boolean" and $additional_items == JSON::false()
MC/DC50%1/2
$additional_items_type eq "boolean" and $additional_items == JSON::false()
$additional_items_type eq "boolean"
$additional_items == JSON::false()
Truth table66%2/3
A and B
A= $additional_items_type eq "boolean"B= $additional_items == JSON::false()
| |||||||||||||||||||||
| 47 | 4 | $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 | 47 | 1; | |||||||||||||||||||