line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Items; |
2
|
4
|
|
|
4
|
|
2491
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
118
|
|
3
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
94
|
|
4
|
4
|
|
|
4
|
|
18
|
use utf8; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
23
|
|
5
|
4
|
|
|
4
|
|
1488
|
use parent qw(Valiemon::Attributes); |
|
4
|
|
|
|
|
605
|
|
|
4
|
|
|
|
|
20
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
275
|
use Carp qw(croak); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
222
|
|
8
|
4
|
|
|
4
|
|
554
|
use List::MoreUtils qw(all); |
|
4
|
|
|
|
|
12402
|
|
|
4
|
|
|
|
|
31
|
|
9
|
4
|
|
|
4
|
|
3141
|
use Valiemon; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1449
|
|
10
|
|
|
|
|
|
|
|
11
|
36
|
|
|
36
|
0
|
114
|
sub attr_name { 'items' } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub is_valid { |
14
|
38
|
|
|
38
|
0
|
92
|
my ($class, $context, $schema, $data) = @_; |
15
|
38
|
100
|
|
|
|
113
|
return 1 unless ref $data eq 'ARRAY'; # ignore |
16
|
|
|
|
|
|
|
|
17
|
36
|
|
|
|
|
67
|
my $items = $schema->{items}; |
18
|
36
|
100
|
|
|
|
112
|
if (ref $items eq 'HASH') { |
|
|
50
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# schema |
20
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
21
|
18
|
|
|
18
|
|
48
|
my $idx = 0; |
22
|
18
|
|
|
|
|
52
|
my $sub_v = $context->sub_validator($items); |
23
|
|
|
|
|
|
|
all { |
24
|
41
|
|
|
|
|
195
|
$context->in($idx, sub { $sub_v->validate($_, $context) }); |
|
41
|
|
|
|
|
104
|
|
25
|
37
|
|
|
|
|
166
|
$idx += 1; |
26
|
18
|
|
|
|
|
159
|
} @$data; |
27
|
18
|
|
|
|
|
107
|
}); |
28
|
|
|
|
|
|
|
} elsif (ref $items eq 'ARRAY') { |
29
|
|
|
|
|
|
|
# index base |
30
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
31
|
18
|
|
|
18
|
|
29
|
my $is_valid = 1; |
32
|
18
|
|
|
|
|
62
|
for (my $i = 0; $i < @$items; $i++) { |
33
|
|
|
|
|
|
|
my $v = $context->in($i, sub { |
34
|
28
|
|
|
|
|
72
|
$context->sub_validator($items->[$i])->validate($data->[$i], $context); |
35
|
28
|
|
|
|
|
154
|
}); |
36
|
26
|
100
|
|
|
|
128
|
unless ($v) { |
37
|
4
|
|
|
|
|
11
|
$is_valid = 0; |
38
|
4
|
|
|
|
|
12
|
last; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
16
|
|
|
|
|
35
|
$is_valid; |
42
|
18
|
|
|
|
|
108
|
}); |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
|
croak 'invalid `items` definition'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |