| 1 | package JSV::Keyword::Draft4::Dependencies; | ||||||||||||||
| 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(escape_json_pointer); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 47 | ▶ | use List::Util qw(first); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | sub instance_type() { INSTANCE_TYPE_OBJECT(); } | ||||||||||||||
| 12 | sub keyword() { "dependencies" } | ||||||||||||||
| 13 | sub keyword_priority() { 10; } | ||||||||||||||
| 14 | |||||||||||||||
| 15 | 54 | ▶ | sub validate { | ||||||||||||
|
Subroutine
validate: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||
| 16 | 54 | my ($class, $context, $schema, $instance) = @_; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 54 | my $dependencies = $class->keyword_value($schema); | |||||||||||||
| 19 | 54 | ▶ | $dependencies ||= {}; | ||||||||||||
|
Condition50%1/2
$dependencies ||= {}
MC/DC0%0/1
$dependencies ||= {}
$dependencies
Truth table50%1/2
A
A= $dependencies
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 54 | for my $property (keys %$dependencies) { | |||||||||||||
| 22 | 62 | ▶ | next unless (exists $instance->{$property}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 34 | local $context->{current_pointer} = $context->{current_pointer} . "/" . escape_json_pointer( $property ); | |||||||||||||
| 25 | local $context->{current_schema_pointer} = | ||||||||||||||
| 26 | 34 | $context->{current_schema_pointer} . "/" . $class->keyword . "/" . escape_json_pointer( $property ); | |||||||||||||
| 27 | |||||||||||||||
| 28 | 34 | ▶ | if (ref $dependencies->{$property} eq "ARRAY") { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 29 | 21 | ▶ | my $found_against_dependency = first { !exists $instance->{$_} } @{$dependencies->{$property}}; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 30 | 21 | ▶ | if ($found_against_dependency) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 15 | $context->log_error(sprintf("%s property has dependency on the %s field", $property, $found_against_dependency)); | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | } | ||||||||||||||
| 34 | elsif (ref $dependencies->{$property} eq "HASH") { | ||||||||||||||
| 35 | 13 | $context->validate($dependencies->{$property}, $instance); | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 47 | 1; | |||||||||||||