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
|
108
|
|
|
108
|
|
69512
|
use strict; |
|
108
|
|
|
|
|
198
|
|
|
108
|
|
|
|
|
2860
|
|
6
|
108
|
|
|
108
|
|
536
|
use warnings; |
|
108
|
|
|
|
|
209
|
|
|
108
|
|
|
|
|
2787
|
|
7
|
|
|
|
|
|
|
|
8
|
108
|
|
|
108
|
|
530
|
use base 'Validation::Class::Directive'; |
|
108
|
|
|
|
|
183
|
|
|
108
|
|
|
|
|
7570
|
|
9
|
|
|
|
|
|
|
|
10
|
108
|
|
|
108
|
|
578
|
use Validation::Class::Util; |
|
108
|
|
|
|
|
210
|
|
|
108
|
|
|
|
|
675
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900057'; # 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
|
29
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
15
|
|
|
|
|
33
|
my ($proto, $field, $param) = @_; |
60
|
|
|
|
|
|
|
|
61
|
15
|
100
|
66
|
|
|
110
|
if (defined $field->{validation} && defined $param) { |
62
|
|
|
|
|
|
|
|
63
|
12
|
|
|
|
|
41
|
my $context = $proto->stash->{'validation.context'}; |
64
|
|
|
|
|
|
|
|
65
|
12
|
|
|
|
|
45
|
my $count = ($proto->errors->count+$field->errors->count); |
66
|
12
|
100
|
|
|
|
42
|
my $failed = !$field->validation->($context,$field,$proto->params)?1:0; |
67
|
12
|
50
|
|
|
|
101
|
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
|
|
|
84
|
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
|
|
|
|
|
25
|
$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
|
|
|
|
|
58
|
return $self; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |