| 1 | package JSV::Keyword::Draft4::UniqueItems; | ||||||||||
| 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 List::MoreUtils qw(uniq); | ||||||||
|
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 | |||||||||||
| 11 | sub instance_type() { INSTANCE_TYPE_ARRAY(); } | ||||||||||
| 12 | sub keyword() { "uniqueItems" } | ||||||||||
| 13 | sub keyword_priority() { 10; } | ||||||||||
| 14 | |||||||||||
| 15 | 34 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 16 | 34 | my ($class, $context, $schema, $instance) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 34 | my $keyword_value = $class->keyword_value($schema); | |||||||||
| 19 | |||||||||||
| 20 | 34 | ▶ | if ($keyword_value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 34 | $context->json->canonical(1); | |||||||||
| 22 | my @unique = uniq map { | ||||||||||
| 23 | 34 | $context->json->encode($_) | |||||||||
| 24 | } @$instance; | ||||||||||
| 25 | |||||||||||
| 26 | 34 | ▶ | if (scalar @unique != scalar @$instance) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 16 | $context->log_error("The instance array is not unique"); | |||||||||
| 28 | } | ||||||||||
| 29 | 34 | $context->json->canonical(0); | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 47 | 1; | |||||||||