| 1 | package Valiemon::Attributes::AdditionalItems; | ||||||||||||||||||||||||||||
| 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 Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use List::MoreUtils qw(all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Valiemon; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | sub attr_name { 'additionalItems' } | ||||||||||||||||||||||||||
|
Subroutine
attr_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub is_valid { | ||||||||||||||||||||||||||||
| 14 | 14 | ▶ | my ($class, $context, $schema, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 14 | ▶ | return 1 unless ref $data eq 'ARRAY'; # ignore | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | my $items = $schema->{items}; | |||||||||||||||||||||||||||
| 18 | 12 | my $additionalItems = $schema->{additionalItems}; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # `additionalItems` works only when `items` is present and its type is array | ||||||||||||||||||||||||||||
| 21 | 12 | ▶ | return 1 unless ref $items eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | ▶ | if (ref $additionalItems eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 24 | # schema | ||||||||||||||||||||||||||||
| 25 | return $context->in_attr($class, sub { | ||||||||||||||||||||||||||||
| 26 | 4 | ▶ | my $idx = 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 4 | my $n = scalar @$items; | |||||||||||||||||||||||||||
| 28 | 4 | my $sub_v = $context->sub_validator($additionalItems); | |||||||||||||||||||||||||||
| 29 | all { | ||||||||||||||||||||||||||||
| 30 | # Initial n items are validated by `items` | ||||||||||||||||||||||||||||
| 31 | 16 | ▶ | if ($idx >= $n) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 14 | ▶ | $context->in($idx, sub { $sub_v->validate($_, $context) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 16 | $idx += 1; | |||||||||||||||||||||||||||
| 35 | 4 | } @$data; | |||||||||||||||||||||||||||
| 36 | 4 | }); | |||||||||||||||||||||||||||
| 37 | } elsif (ref $additionalItems eq 'ARRAY') { | ||||||||||||||||||||||||||||
| 38 | 0 | croak sprintf '`additionalItems` must be an object or boolean value at %s.', | |||||||||||||||||||||||||||
| 39 | $context->position; | ||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||
| 41 | # boolean | ||||||||||||||||||||||||||||
| 42 | return $context->in_attr($class, sub { | ||||||||||||||||||||||||||||
| 43 | 4 | ▶ | if (!$context->prims->is_boolean($additionalItems)) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | croak sprintf '`additionalItems` must be an object or boolean value at %s.', | |||||||||||||||||||||||||||
| 45 | $context->position; | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 4 | ▶ | return 0 if !$additionalItems && (scalar @$data > scalar @$items); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $additionalItems and scalar @$data > scalar @$items
MC/DC50%1/2
not $additionalItems and scalar @$data > scalar @$items
not $additionalItems
scalar @$data > scalar @$items
Truth table66%2/3
not(A) and B
A= not $additionalItemsB= scalar @$data > scalar @$items
| |||||||||||||||||||||||||||||
| 48 | 2 | return 1; | |||||||||||||||||||||||||||
| 49 | 4 | }); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | 1; | |||||||||||||||||||||||||||