line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Validation Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Validation; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
54347
|
use strict; |
|
109
|
|
|
|
|
316
|
|
|
109
|
|
|
|
|
3455
|
|
6
|
109
|
|
|
109
|
|
705
|
use warnings; |
|
109
|
|
|
|
|
259
|
|
|
109
|
|
|
|
|
2991
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
576
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
241
|
|
|
109
|
|
|
|
|
10998
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
832
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
306
|
|
|
109
|
|
|
|
|
725
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 0; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'message' => '%s could not be validated'; |
19
|
|
|
|
|
|
|
# ensure most core directives execute before this one |
20
|
|
|
|
|
|
|
has 'dependencies' => sub {{ |
21
|
|
|
|
|
|
|
normalization => [], |
22
|
|
|
|
|
|
|
validation => [qw( |
23
|
|
|
|
|
|
|
alias |
24
|
|
|
|
|
|
|
between |
25
|
|
|
|
|
|
|
default |
26
|
|
|
|
|
|
|
depends_on |
27
|
|
|
|
|
|
|
error |
28
|
|
|
|
|
|
|
errors |
29
|
|
|
|
|
|
|
filtering |
30
|
|
|
|
|
|
|
filters |
31
|
|
|
|
|
|
|
label |
32
|
|
|
|
|
|
|
length |
33
|
|
|
|
|
|
|
matches |
34
|
|
|
|
|
|
|
max_alpha |
35
|
|
|
|
|
|
|
max_digits |
36
|
|
|
|
|
|
|
max_length |
37
|
|
|
|
|
|
|
max_sum |
38
|
|
|
|
|
|
|
min_alpha |
39
|
|
|
|
|
|
|
min_digits |
40
|
|
|
|
|
|
|
min_length |
41
|
|
|
|
|
|
|
min_sum |
42
|
|
|
|
|
|
|
mixin |
43
|
|
|
|
|
|
|
mixin_field |
44
|
|
|
|
|
|
|
multiples |
45
|
|
|
|
|
|
|
name |
46
|
|
|
|
|
|
|
options |
47
|
|
|
|
|
|
|
pattern |
48
|
|
|
|
|
|
|
readonly |
49
|
|
|
|
|
|
|
required |
50
|
|
|
|
|
|
|
toggle |
51
|
|
|
|
|
|
|
value |
52
|
|
|
|
|
|
|
)] |
53
|
|
|
|
|
|
|
}}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub validate { |
56
|
|
|
|
|
|
|
|
57
|
15
|
|
|
15
|
0
|
41
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
15
|
|
|
|
|
45
|
my ($proto, $field, $param) = @_; |
60
|
|
|
|
|
|
|
|
61
|
15
|
100
|
66
|
|
|
91
|
if (defined $field->{validation} && defined $param) { |
62
|
|
|
|
|
|
|
|
63
|
12
|
|
|
|
|
36
|
my $context = $proto->stash->{'validation.context'}; |
64
|
|
|
|
|
|
|
|
65
|
12
|
|
|
|
|
53
|
my $count = ($proto->errors->count+$field->errors->count); |
66
|
12
|
100
|
|
|
|
76
|
my $failed = !$field->validation->($context,$field,$proto->params)?1:0; |
67
|
12
|
50
|
|
|
|
127
|
my $errors = ($proto->errors->count+$field->errors->count)>$count ?1:0; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# error handling; did the validation routine pass or fail? |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# validation passed with no errors |
72
|
12
|
100
|
66
|
|
|
109
|
if (!$failed && !$errors) { |
|
|
50
|
33
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
73
|
|
|
|
|
|
|
# noop |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# validation failed with no errors |
77
|
|
|
|
|
|
|
elsif ($failed && !$errors) { |
78
|
2
|
|
|
|
|
36
|
$self->error(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# validation passed with errors |
82
|
|
|
|
|
|
|
elsif (!$failed && $errors) { |
83
|
|
|
|
|
|
|
# noop -- but acknowledge errors have been set |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# validation failed with errors |
87
|
|
|
|
|
|
|
elsif ($failed && $errors) { |
88
|
|
|
|
|
|
|
# assume errors have been set from inside the validation routine |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
52
|
return $self; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |