line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Items; |
2
|
2
|
|
|
2
|
|
1341
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
55
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
6
|
use utf8; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
15
|
|
5
|
2
|
|
|
2
|
|
14179
|
use parent qw(Valiemon::Attributes); |
|
2
|
|
|
|
|
652
|
|
|
2
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
125
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
134
|
|
8
|
2
|
|
|
2
|
|
1265
|
use List::MoreUtils qw(all); |
|
2
|
|
|
|
|
23312
|
|
|
2
|
|
|
|
|
19
|
|
9
|
2
|
|
|
2
|
|
1206
|
use Valiemon; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
517
|
|
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
0
|
35
|
sub attr_name { 'items' } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub is_valid { |
14
|
10
|
|
|
10
|
0
|
23
|
my ($class, $context, $schema, $data) = @_; |
15
|
10
|
50
|
|
|
|
30
|
return 1 unless ref $data eq 'ARRAY'; # ignore |
16
|
|
|
|
|
|
|
|
17
|
10
|
|
|
|
|
21
|
my $items = $schema->{items}; |
18
|
10
|
100
|
|
|
|
28
|
if (ref $items eq 'HASH') { |
|
|
50
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# schema |
20
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
21
|
8
|
|
|
8
|
|
12
|
my $idx = 0; |
22
|
8
|
|
|
|
|
26
|
my $sub_v = $context->sub_validator($items); |
23
|
|
|
|
|
|
|
all { |
24
|
17
|
|
|
|
|
76
|
$context->in($idx, sub { $sub_v->validate($_, $context) }); |
|
17
|
|
|
|
|
54
|
|
25
|
17
|
|
|
|
|
65
|
$idx += 1; |
26
|
8
|
|
|
|
|
84
|
} @$data; |
27
|
8
|
|
|
|
|
65
|
}); |
28
|
|
|
|
|
|
|
} elsif (ref $items eq 'ARRAY') { |
29
|
|
|
|
|
|
|
# index base |
30
|
|
|
|
|
|
|
return $context->in_attr($class, sub { |
31
|
2
|
|
|
2
|
|
4
|
my $is_valid = 1; |
32
|
2
|
|
|
|
|
8
|
for (my $i = 0; $i < @$items; $i++) { |
33
|
|
|
|
|
|
|
my $v = $context->in($i, sub { |
34
|
5
|
|
|
|
|
16
|
$context->sub_validator($items->[$i])->validate($data->[$i], $context); |
35
|
5
|
|
|
|
|
31
|
}); |
36
|
5
|
100
|
|
|
|
32
|
unless ($v) { |
37
|
1
|
|
|
|
|
2
|
$is_valid = 0; |
38
|
1
|
|
|
|
|
3
|
last; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
2
|
|
|
|
|
6
|
$is_valid; |
42
|
2
|
|
|
|
|
16
|
}); |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
|
croak 'invalid `items` definition'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |