line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Items; |
2
|
4
|
|
|
4
|
|
2053
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
104
|
|
3
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
92
|
|
4
|
4
|
|
|
4
|
|
14
|
use utf8; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
18
|
|
5
|
4
|
|
|
4
|
|
1606
|
use parent qw(Valiemon::Attributes); |
|
4
|
|
|
|
|
1000
|
|
|
4
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
191
|
use Carp qw(croak); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
187
|
|
8
|
4
|
|
|
4
|
|
844
|
use List::MoreUtils qw(all); |
|
4
|
|
|
|
|
15039
|
|
|
4
|
|
|
|
|
31
|
|
9
|
4
|
|
|
4
|
|
1710
|
use Valiemon; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
967
|
|
10
|
|
|
|
|
|
|
|
11
|
36
|
|
|
36
|
0
|
71
|
sub attr_name { 'items' } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub is_valid { |
14
|
38
|
|
|
38
|
0
|
45
|
my ($class, $context, $schema, $data) = @_; |
15
|
38
|
100
|
|
|
|
78
|
return 1 unless ref $data eq 'ARRAY'; # ignore |
16
|
|
|
|
|
|
|
|
17
|
36
|
|
|
|
|
49
|
my $items = $schema->{items}; |
18
|
36
|
100
|
|
|
|
76
|
if (ref $items eq 'HASH') { |
|
|
50
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# schema |
20
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
21
|
18
|
|
|
18
|
|
16
|
my $idx = 0; |
22
|
18
|
|
|
|
|
35
|
my $sub_v = $context->sub_validator($items); |
23
|
|
|
|
|
|
|
all { |
24
|
41
|
|
|
|
|
121
|
$context->in($idx, sub { $sub_v->validate($_, $context) }); |
|
41
|
|
|
|
|
80
|
|
25
|
37
|
|
|
|
|
84
|
$idx += 1; |
26
|
18
|
|
|
|
|
146
|
} @$data; |
27
|
18
|
|
|
|
|
79
|
}); |
28
|
|
|
|
|
|
|
} elsif (ref $items eq 'ARRAY') { |
29
|
|
|
|
|
|
|
# index base |
30
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
31
|
18
|
|
|
18
|
|
14
|
my $is_valid = 1; |
32
|
18
|
|
|
|
|
41
|
for (my $i = 0; $i < @$items; $i++) { |
33
|
|
|
|
|
|
|
my $v = $context->in($i, sub { |
34
|
28
|
|
|
|
|
48
|
$context->sub_validator($items->[$i])->validate($data->[$i], $context); |
35
|
28
|
|
|
|
|
90
|
}); |
36
|
26
|
100
|
|
|
|
97
|
unless ($v) { |
37
|
4
|
|
|
|
|
4
|
$is_valid = 0; |
38
|
4
|
|
|
|
|
8
|
last; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
16
|
|
|
|
|
20
|
$is_valid; |
42
|
18
|
|
|
|
|
80
|
}); |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
|
croak 'invalid `items` definition'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |