line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
17
|
|
|
17
|
|
1090
|
use warnings; |
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
429
|
|
4
|
17
|
|
|
17
|
|
75
|
|
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
375
|
|
5
|
|
|
|
|
|
|
use Moo; |
6
|
17
|
|
|
17
|
|
111
|
use Carp; |
|
17
|
|
|
|
|
61
|
|
|
17
|
|
|
|
|
80
|
|
7
|
17
|
|
|
17
|
|
4634
|
use Types::Standard qw(InstanceOf); |
|
17
|
|
|
|
|
44
|
|
|
17
|
|
|
|
|
889
|
|
8
|
17
|
|
|
17
|
|
101
|
use namespace::clean; |
|
17
|
|
|
|
|
34
|
|
|
17
|
|
|
|
|
132
|
|
9
|
17
|
|
|
17
|
|
8019
|
|
|
17
|
|
|
|
|
38
|
|
|
17
|
|
|
|
|
109
|
|
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
|
23863
|
if (ref $profile ne 'HASH') { |
27
|
|
|
|
|
|
|
Carp::croak("Profile should be a HashRef\n") |
28
|
19
|
50
|
|
|
|
127
|
} |
29
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
my $success = 0; |
31
|
|
|
|
|
|
|
my %profile = %{ $profile }; |
32
|
19
|
|
|
|
|
46
|
my $is_valid; |
33
|
19
|
|
|
|
|
40
|
my @valid; |
|
19
|
|
|
|
|
110
|
|
34
|
19
|
|
|
|
|
84
|
my @invalid; |
35
|
|
|
|
|
|
|
|
36
|
19
|
|
|
|
|
0
|
for my $field (keys %profile) { |
37
|
|
|
|
|
|
|
$is_valid = 1; |
38
|
19
|
|
|
|
|
72
|
my @validators = @{ $profile{$field} }; |
39
|
41
|
|
|
|
|
86
|
|
40
|
41
|
|
|
|
|
76
|
for my $validator_declaration (@validators) { |
|
41
|
|
|
|
|
167
|
|
41
|
|
|
|
|
|
|
if (my ($name, $params) = $self->_split_validator_declaration($validator_declaration)) { |
42
|
41
|
|
|
|
|
99
|
my $validator = $self->registry->get($name); |
43
|
65
|
50
|
|
|
|
210
|
|
44
|
65
|
|
|
|
|
427
|
if (not $validator->validate($field, $input, split(',', $params))) { |
45
|
|
|
|
|
|
|
push @invalid, [ $field, $name, $params ]; |
46
|
65
|
100
|
|
|
|
398
|
$is_valid = 0; |
47
|
23
|
|
|
|
|
132
|
} |
48
|
23
|
|
|
|
|
66
|
|
49
|
|
|
|
|
|
|
if (!$is_valid && $validator->stop_on_fail) { |
50
|
|
|
|
|
|
|
last; |
51
|
65
|
100
|
100
|
|
|
640
|
} |
52
|
9
|
|
|
|
|
62
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($is_valid == 1) { |
56
|
|
|
|
|
|
|
push @valid, $field; |
57
|
41
|
100
|
|
|
|
272
|
} |
58
|
18
|
|
|
|
|
99
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if (not @invalid) { |
61
|
|
|
|
|
|
|
$success = 1; |
62
|
19
|
100
|
|
|
|
314
|
} |
63
|
5
|
|
|
|
|
18
|
|
64
|
|
|
|
|
|
|
return ($success, \@valid, \@invalid) |
65
|
|
|
|
|
|
|
} |
66
|
19
|
|
|
|
|
495
|
|
67
|
|
|
|
|
|
|
# Because validator signatures could be validator:params, we need to split it. |
68
|
|
|
|
|
|
|
return ($_[1] =~ /([^:]+):?(.*)/); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
65
|
|
|
65
|
|
549
|
1; |