blib/lib/Valiemon/Attributes/AdditionalItems.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 85.7% 12 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 89.7% 70 / 78 CC 9 SCAR 9.9
CC
9
Cov
92%
is_valid
5.1
__ANON__
4.3
__ANON__
2.0
CRAP 2.7
« blib/lib/Valiemon.pm ↑ Summary blib/lib/Valiemon/Attributes/Required.pm »
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
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 2 12 14
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
BranchTrueFalseTotal
unless ref $items eq "ARRAY" 4 8 12
22  
23 8 ▶ if (ref $additionalItems eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $additionalItems eq 'HASH') { } 4 4 8
elsif (ref $additionalItems eq 'ARRAY') { } 0 4 4
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
BranchTrueFalseTotal
if ($idx >= $n) 14 2 16
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
BranchTrueFalseTotal
unless ($context->prims->is_boolean($additionalItems)) 0 4 4
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
BranchTrueFalseTotal
if not $additionalItems and scalar @$data > scalar @$items 2 2 4
Condition66%2/3
not $additionalItems and scalar @$data > scalar @$items
!ll&&!rl&&r
022
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
ABresult
0X0
100
111
48 2 return 1;
49 4 });
50 }
51 }
52  
53 2 1;
« blib/lib/Valiemon.pm ↑ Summary blib/lib/Valiemon/Attributes/Required.pm »