line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
17
|
|
|
17
|
|
769
|
use warnings; |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
408
|
|
4
|
17
|
|
|
17
|
|
68
|
|
|
17
|
|
|
|
|
32
|
|
|
17
|
|
|
|
|
308
|
|
5
|
|
|
|
|
|
|
use Moo; |
6
|
17
|
|
|
17
|
|
114
|
use Carp; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
78
|
|
7
|
17
|
|
|
17
|
|
4251
|
use Types::Standard qw(InstanceOf); |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
868
|
|
8
|
17
|
|
|
17
|
|
89
|
use namespace::clean; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
116
|
|
9
|
17
|
|
|
17
|
|
7042
|
|
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
228
|
|
10
|
|
|
|
|
|
|
has config => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
isa => InstanceOf['Dancer2::Plugin::FormValidator::Config'], |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has registry => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => InstanceOf['Dancer2::Plugin::FormValidator::Registry'], |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Apply validators to each fields. |
23
|
|
|
|
|
|
|
# Collect valid and invalid fields. |
24
|
|
|
|
|
|
|
my ($self, $profile, $input) = @_; |
25
|
|
|
|
|
|
|
|
26
|
19
|
|
|
19
|
0
|
21642
|
if (ref $profile ne 'HASH') { |
27
|
|
|
|
|
|
|
Carp::croak("Profile should be a HashRef\n") |
28
|
19
|
50
|
|
|
|
92
|
} |
29
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
my $success = 0; |
31
|
|
|
|
|
|
|
my %profile = %{ $profile }; |
32
|
19
|
|
|
|
|
37
|
my $is_valid; |
33
|
19
|
|
|
|
|
34
|
my @valid; |
|
19
|
|
|
|
|
94
|
|
34
|
19
|
|
|
|
|
69
|
my @invalid; |
35
|
|
|
|
|
|
|
|
36
|
19
|
|
|
|
|
0
|
for my $field (keys %profile) { |
37
|
|
|
|
|
|
|
$is_valid = 1; |
38
|
19
|
|
|
|
|
62
|
my @validators = @{ $profile{$field} }; |
39
|
41
|
|
|
|
|
85
|
|
40
|
41
|
|
|
|
|
74
|
for my $validator_declaration (@validators) { |
|
41
|
|
|
|
|
155
|
|
41
|
|
|
|
|
|
|
if (my ($name, $params) = $self->_split_validator_declaration($validator_declaration)) { |
42
|
41
|
|
|
|
|
100
|
my $validator = $self->registry->get($name); |
43
|
65
|
50
|
|
|
|
202
|
|
44
|
65
|
|
|
|
|
357
|
if (not $validator->validate($field, $input, split(',', $params))) { |
45
|
|
|
|
|
|
|
push @invalid, [ $field, $name, $params ]; |
46
|
65
|
100
|
|
|
|
376
|
$is_valid = 0; |
47
|
23
|
|
|
|
|
130
|
} |
48
|
23
|
|
|
|
|
55
|
|
49
|
|
|
|
|
|
|
if (!$is_valid && $validator->stop_on_fail) { |
50
|
|
|
|
|
|
|
last; |
51
|
65
|
100
|
100
|
|
|
619
|
} |
52
|
9
|
|
|
|
|
68
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($is_valid == 1) { |
56
|
|
|
|
|
|
|
push @valid, $field; |
57
|
41
|
100
|
|
|
|
277
|
} |
58
|
18
|
|
|
|
|
84
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if (not @invalid) { |
61
|
|
|
|
|
|
|
$success = 1; |
62
|
19
|
100
|
|
|
|
104
|
} |
63
|
5
|
|
|
|
|
18
|
|
64
|
|
|
|
|
|
|
return ($success, \@valid, \@invalid) |
65
|
|
|
|
|
|
|
} |
66
|
19
|
|
|
|
|
408
|
|
67
|
|
|
|
|
|
|
# Because validator signatures could be validator:params, we need to split it. |
68
|
|
|
|
|
|
|
return ($_[1] =~ /([^:]+):?(.*)/); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
65
|
|
|
65
|
|
461
|
1; |