| 1 | package JSV::Keyword::Draft4::OneOf; | ||||||||||
| 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 | |||||||||||
| 9 | sub instance_type() { INSTANCE_TYPE_ANY(); } | ||||||||||
| 10 | sub keyword() { "oneOf" } | ||||||||||
| 11 | sub keyword_priority() { 10; } | ||||||||||
| 12 | |||||||||||
| 13 | 20 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 14 | 20 | my ($class, $context, $schema, $instance) = @_; | |||||||||
| 15 | |||||||||||
| 16 | 20 | my $one_of = $class->keyword_value($schema); | |||||||||
| 17 | 20 | my $valid_cnt = 0; | |||||||||
| 18 | |||||||||||
| 19 | 20 | ▶ | if (scalar(@$one_of) == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 1 | my $sub_schema = $one_of->[0]; | |||||||||
| 21 | local $context->{current_schema_pointer} = | ||||||||||
| 22 | 1 | $context->{current_schema_pointer} . "/" . $class->keyword . "/0"; | |||||||||
| 23 | 1 | $context->validate($sub_schema, $instance); | |||||||||
| 24 | 1 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 19 | ▶ | for (my $i = 0, my $l = scalar(@$one_of); $i < $l; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 38 | my $sub_schema = $one_of->[$i]; | |||||||||
| 29 | local $context->{current_schema_pointer} = | ||||||||||
| 30 | 38 | $context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i; | |||||||||
| 31 | 38 | local $context->{errors} = []; | |||||||||
| 32 | 38 | $context->validate($sub_schema, $instance); | |||||||||
| 33 | 38 | ▶ | $valid_cnt += 1 unless scalar @{ $context->{errors} }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 19 | ▶ | unless ($valid_cnt == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 10 | $context->log_error("The instance is not matched to one of schemas"); | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 47 | 1; | |||||||||