line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Required Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Required; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
51168
|
use strict; |
|
109
|
|
|
|
|
234
|
|
|
109
|
|
|
|
|
3029
|
|
6
|
109
|
|
|
109
|
|
521
|
use warnings; |
|
109
|
|
|
|
|
212
|
|
|
109
|
|
|
|
|
2905
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
540
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
211
|
|
|
109
|
|
|
|
|
11095
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
676
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
214
|
|
|
109
|
|
|
|
|
745
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'message' => '%s is required'; |
19
|
|
|
|
|
|
|
has 'dependencies' => sub {{ |
20
|
|
|
|
|
|
|
normalization => [], |
21
|
|
|
|
|
|
|
validation => ['alias', 'toggle'] |
22
|
|
|
|
|
|
|
}}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub before_validation { |
25
|
|
|
|
|
|
|
|
26
|
560
|
|
|
560
|
0
|
1363
|
my ($self, $proto, $field, $param) = @_; |
27
|
|
|
|
|
|
|
|
28
|
560
|
50
|
|
|
|
1491
|
if (defined $field->{required}) { |
29
|
|
|
|
|
|
|
|
30
|
560
|
100
|
100
|
|
|
2029
|
if ($field->{required} && (! defined $param || $param eq '')) { |
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
36
|
|
|
|
|
265
|
$self->error($proto, $field); |
33
|
36
|
50
|
|
|
|
117
|
$proto->stash->{'validation.bypass_event'}++ |
34
|
|
|
|
|
|
|
unless $proto->ignore_intervention; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
560
|
|
|
|
|
1291
|
return $self; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub normalize { |
45
|
|
|
|
|
|
|
|
46
|
1009
|
|
|
1009
|
0
|
2254
|
my ($self, $proto, $field, $param) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# by default, field validation is optional |
49
|
|
|
|
|
|
|
|
50
|
1009
|
100
|
|
|
|
2631
|
$field->{required} = 0 unless defined $field->{required}; |
51
|
|
|
|
|
|
|
|
52
|
1009
|
|
|
|
|
2186
|
return $self; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |