| 1 | package JSONSchema::Validator::Constraints::Draft6; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: JSON Schema Draft6 specification constraints | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use JSONSchema::Validator::JSONPointer 'json_pointer'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use JSONSchema::Validator::Error 'error'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use JSONSchema::Validator::Util qw(is_type serialize unbool); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use parent 'JSONSchema::Validator::Constraints::Draft4'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | # params: $self, $value, $type, $strict | ||||||||||||||||||||||||||||||||||||||
| 15 | 1219 | ▶ | sub check_type { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
check_type: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 16 | 1219 | ▶ | if ($_[2] eq 'integer') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | return is_type($_[1], 'number', $_[3] // $_[0]->strict) && int($_[1]) == $_[1]; | ||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
is_type($_[1], 'number', $_[3] // $_[0]->strict) && int $_[1] == $_[1]
$_[3] // $_[0]->strict
MC/DC50%1/2
is_type($_[1], 'number', $_[3] // $_[0]->strict) && int $_[1] == $_[1]
is_type($_[1], 'number', $_[3] // $_[0]->strict)
int $_[1] == $_[1]
MC/DC0%0/2
$_[3] // $_[0]->strict
$_[3]
$_[0]->strict
Truth table66%2/3
A && B
A= is_type($_[1], 'number', $_[3] // $_[0]->strict)B= int $_[1] == $_[1]
Truth table33%1/3
A // B
A= $_[3]B= $_[0]->strict
| |||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||
| 19 | 1208 | ▶ | return is_type($_[1], $_[2], $_[3] // $_[0]->strict); | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[3] // $_[0]->strict
MC/DC0%0/2
$_[3] // $_[0]->strict
$_[3]
$_[0]->strict
Truth table66%2/3
A // B
A= $_[3]B= $_[0]->strict
| |||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | sub exclusiveMaximum { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
exclusiveMaximum: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 23 | 7 | my ($self, $instance, $exclusiveMaximum, $schema, $instance_path, $schema_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | return 1 unless $self->check_type($instance, 'number'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | return 1 if $instance < $exclusiveMaximum; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 5 | push @{$data->{errors}}, error( | |||||||||||||||||||||||||||||||||||||
| 29 | message => "${instance} is equal or greater than ${exclusiveMaximum}", | ||||||||||||||||||||||||||||||||||||||
| 30 | instance_path => $instance_path, | ||||||||||||||||||||||||||||||||||||||
| 31 | schema_path => $schema_path | ||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||
| 33 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | sub exclusiveMinimum { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
exclusiveMinimum: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my ($self, $instance, $exclusiveMinimum, $schema, $instance_path, $schema_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | return 1 unless $self->check_type($instance, 'number'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | return 1 if $instance > $exclusiveMinimum; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 2 | push @{$data->{errors}}, error( | |||||||||||||||||||||||||||||||||||||
| 43 | message => "${instance} is equal or less than ${exclusiveMinimum}", | ||||||||||||||||||||||||||||||||||||||
| 44 | instance_path => $instance_path, | ||||||||||||||||||||||||||||||||||||||
| 45 | schema_path => $schema_path | ||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||
| 47 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub propertyNames { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
propertyNames: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my ($self, $instance, $propertyNames, $schema, $instance_path, $schema_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | return 1 unless $self->check_type($instance, 'object'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $result = 1; | |||||||||||||||||||||||||||||||||||||
| 55 | 2 | for my $p (keys %$instance) { | |||||||||||||||||||||||||||||||||||||
| 56 | 4 | my $ipath = json_pointer->append($instance_path, $p); | |||||||||||||||||||||||||||||||||||||
| 57 | 4 | my $r = $self->validator->_validate_schema($p, $propertyNames, $ipath, $schema_path, $data); | |||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | $result = 0 unless $r; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||
| 60 | 2 | return $result; | |||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | sub contains { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 64 | 6 | my ($self, $instance, $contains, $schema, $instance_path, $schema_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | return 1 unless $self->check_type($instance, 'array'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 6 | my $errors = $data->{errors}; | |||||||||||||||||||||||||||||||||||||
| 68 | 6 | my $local_errors = []; | |||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 6 | my $result = 0; | |||||||||||||||||||||||||||||||||||||
| 71 | 6 | for my $idx (0 .. $#{$instance}) { | |||||||||||||||||||||||||||||||||||||
| 72 | 20 | $data->{errors} = []; | |||||||||||||||||||||||||||||||||||||
| 73 | 20 | my $ipath = json_pointer->append($instance_path, $idx); | |||||||||||||||||||||||||||||||||||||
| 74 | 20 | $result = $self->validator->_validate_schema($instance->[$idx], $contains, $ipath, $schema_path, $data); | |||||||||||||||||||||||||||||||||||||
| 75 | 20 | ▶ | unless ($result) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 76 | 17 | push @{$local_errors}, error( | |||||||||||||||||||||||||||||||||||||
| 77 | message => qq'${idx} part of "contains" has errors', | ||||||||||||||||||||||||||||||||||||||
| 78 | context => $data->{errors}, | ||||||||||||||||||||||||||||||||||||||
| 79 | 17 | instance_path => $ipath, | |||||||||||||||||||||||||||||||||||||
| 80 | schema_path => $schema_path | ||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | 20 | ▶ | last if $result; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||
| 85 | 6 | $data->{errors} = $errors; | |||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | return 1 if $result; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 3 | push @{$data->{errors}}, error( | |||||||||||||||||||||||||||||||||||||
| 89 | message => 'No elems of instance satisfy schema of "contains"', | ||||||||||||||||||||||||||||||||||||||
| 90 | context => $local_errors, | ||||||||||||||||||||||||||||||||||||||
| 91 | instance_path => $instance_path, | ||||||||||||||||||||||||||||||||||||||
| 92 | schema_path => $schema_path | ||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||
| 94 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | 10 | ▶ | sub const { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
const: called CC=14 SCAR=33.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 98 | 10 | my ($self, $instance, $const, $schema, $instance_path, $schema_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | 10 | my $result = 0; | |||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | # schema must have strict check | ||||||||||||||||||||||||||||||||||||||
| 103 | 10 | ▶ | if ($self->check_type($const, 'boolean', 1)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $result = $self->check_type($instance, 'boolean') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 105 | ? unbool($instance) eq unbool($const) | ||||||||||||||||||||||||||||||||||||||
| 106 | : 0 | ||||||||||||||||||||||||||||||||||||||
| 107 | ▶ | } elsif ($self->check_type($const, 'object', 1) || $self->check_type($const, 'array', 1)) { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->check_type($const, "object", 1) or $self->check_type($const, "array", 1)
MC/DC50%1/2
$self->check_type($const, "object", 1) or $self->check_type($const, "array", 1)
$self->check_type($const, "object", 1)
$self->check_type($const, "array", 1)
Truth table66%2/3
A or B
A= $self->check_type($const, "object", 1)B= $self->check_type($const, "array", 1)
| |||||||||||||||||||||||||||||||||||||||
| 108 | 2 | ▶ | $result = $self->check_type($instance, 'object') || | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->check_type($instance, "object") or $self->check_type($instance, "array")
MC/DC0%0/2
$self->check_type($instance, "object") or $self->check_type($instance, "array")
$self->check_type($instance, "object")
$self->check_type($instance, "array")
Truth table33%1/3
A or B
A= $self->check_type($instance, "object")B= $self->check_type($instance, "array")
| |||||||||||||||||||||||||||||||||||||||
| 109 | $self->check_type($instance, 'array') | ||||||||||||||||||||||||||||||||||||||
| 110 | ? serialize($instance) eq serialize($const) | ||||||||||||||||||||||||||||||||||||||
| 111 | : 0; | ||||||||||||||||||||||||||||||||||||||
| 112 | } elsif ($self->check_type($const, 'number', 1)) { | ||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | $result = $self->check_type($instance, 'number') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 114 | ? $const == $instance | ||||||||||||||||||||||||||||||||||||||
| 115 | : 0; | ||||||||||||||||||||||||||||||||||||||
| 116 | ▶ | } elsif (defined $const && defined $instance) { | |||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $const and defined $instance
MC/DC0%0/2
defined $const and defined $instance
defined $const
defined $instance
Truth table33%1/3
A and B
A= defined $constB= defined $instance
| |||||||||||||||||||||||||||||||||||||||
| 117 | 4 | $result = $const eq $instance; | |||||||||||||||||||||||||||||||||||||
| 118 | ▶ | } elsif (!defined $const && !defined $instance) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $const || defined $instance
MC/DC0%0/2
defined $const || defined $instance
defined $const
defined $instance
Truth table0%0/3
A || B
A= defined $constB= defined $instance
| |||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $result = 1; | |||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | 10 | ▶ | return 1 if $result; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 5 | push @{$data->{errors}}, error( | |||||||||||||||||||||||||||||||||||||
| 125 | message => "instance is not equal const", | ||||||||||||||||||||||||||||||||||||||
| 126 | instance_path => $instance_path, | ||||||||||||||||||||||||||||||||||||||
| 127 | schema_path => $schema_path | ||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||
| 129 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | 11 | 1; | |||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||||||||||||