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
|
108
|
|
|
108
|
|
66441
|
use strict; |
|
108
|
|
|
|
|
224
|
|
|
108
|
|
|
|
|
3031
|
|
6
|
108
|
|
|
108
|
|
614
|
use warnings; |
|
108
|
|
|
|
|
231
|
|
|
108
|
|
|
|
|
2937
|
|
7
|
|
|
|
|
|
|
|
8
|
108
|
|
|
108
|
|
537
|
use base 'Validation::Class::Directive'; |
|
108
|
|
|
|
|
272
|
|
|
108
|
|
|
|
|
7739
|
|
9
|
|
|
|
|
|
|
|
10
|
108
|
|
|
108
|
|
583
|
use Validation::Class::Util; |
|
108
|
|
|
|
|
223
|
|
|
108
|
|
|
|
|
721
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900057'; # 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
|
555
|
|
|
555
|
0
|
1134
|
my ($self, $proto, $field, $param) = @_; |
27
|
|
|
|
|
|
|
|
28
|
555
|
50
|
|
|
|
1615
|
if (defined $field->{required}) { |
29
|
|
|
|
|
|
|
|
30
|
555
|
100
|
100
|
|
|
2499
|
if ($field->{required} && (! defined $param || $param eq '')) { |
|
|
|
66
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
35
|
|
|
|
|
275
|
$self->error($proto, $field); |
33
|
35
|
50
|
|
|
|
135
|
$proto->stash->{'validation.bypass_event'}++ |
34
|
|
|
|
|
|
|
unless $proto->ignore_intervention; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
555
|
|
|
|
|
1675
|
return $self; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub normalize { |
45
|
|
|
|
|
|
|
|
46
|
1002
|
|
|
1002
|
0
|
1845
|
my ($self, $proto, $field, $param) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# by default, field validation is optional |
49
|
|
|
|
|
|
|
|
50
|
1002
|
100
|
|
|
|
2890
|
$field->{required} = 0 unless defined $field->{required}; |
51
|
|
|
|
|
|
|
|
52
|
1002
|
|
|
|
|
2816
|
return $self; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |