« blib/lib/Valiemon/Attributes/Items.pm
↑ Summary
blib/lib/Valiemon/Attributes/AdditionalProperties.pm »
| 1 | package Valiemon::Attributes::UniqueItems; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use parent qw(Valiemon::Attributes); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use List::MoreUtils qw(any); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 26 | ▶ | sub attr_name { 'uniqueItems' } | ||||||||
|
Subroutine
attr_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 10 | |||||||||||
| 11 | sub is_valid { | ||||||||||
| 12 | 26 | ▶ | my ($class, $context, $schema, $data) = @_; | ||||||||
|
Subroutine
is_valid: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 13 | |||||||||||
| 14 | 26 | ▶ | return 1 unless ref $data eq 'ARRAY'; # ignore | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 26 | ▶ | return 1 unless $schema->{uniqueItems}; # skip on false | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | $context->in_attr($class, sub { | ||||||||||
| 18 | 26 | ▶ | my $unique_data = []; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 19 | 26 | for my $datum (@$data) { | |||||||||
| 20 | 64 | ▶ | return 0 if any { $context->prims->is_equal($_, $datum) } @$unique_data; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 21 | 52 | push @$unique_data, $datum; | |||||||||
| 22 | } | ||||||||||
| 23 | 14 | return 1; | |||||||||
| 24 | 26 | }); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 2 | 1; | |||||||||