line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Toggle Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Toggle; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
43701
|
use strict; |
|
109
|
|
|
|
|
243
|
|
|
109
|
|
|
|
|
2689
|
|
6
|
109
|
|
|
109
|
|
483
|
use warnings; |
|
109
|
|
|
|
|
204
|
|
|
109
|
|
|
|
|
2413
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
455
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
201
|
|
|
109
|
|
|
|
|
9151
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
651
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
223
|
|
|
109
|
|
|
|
|
576
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 0; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub before_validation { |
20
|
|
|
|
|
|
|
|
21
|
32
|
|
|
32
|
0
|
86
|
my ($self, $proto, $field, $param) = @_; |
22
|
|
|
|
|
|
|
|
23
|
32
|
50
|
|
|
|
121
|
if (defined $field->{toggle}) { |
24
|
|
|
|
|
|
|
|
25
|
32
|
|
100
|
|
|
95
|
my $stash = $proto->stash->{'directive.toggle'} ||= {}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# to be restored after validation |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$stash->{$field->{name}}->{'required'} = |
30
|
32
|
100
|
|
|
|
187
|
defined $field->{required} ? $field->{required} == 0 ? 0 : 1 : 0; |
|
|
50
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
32
|
100
|
|
|
|
255
|
$field->{required} = 1 if ($field->{toggle} =~ /^(\+|1)$/); |
33
|
32
|
100
|
|
|
|
132
|
$field->{required} = 0 if ($field->{toggle} =~ /^(\-|0)$/); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
32
|
|
|
|
|
80
|
return $self; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub after_validation { |
42
|
|
|
|
|
|
|
|
43
|
32
|
|
|
32
|
0
|
91
|
my ($self, $proto, $field, $param) = @_; |
44
|
|
|
|
|
|
|
|
45
|
32
|
50
|
|
|
|
99
|
if (defined $field->{toggle}) { |
46
|
|
|
|
|
|
|
|
47
|
32
|
|
50
|
|
|
90
|
my $stash = $proto->stash->{'directive.toggle'} ||= {}; |
48
|
|
|
|
|
|
|
|
49
|
32
|
50
|
|
|
|
122
|
if (defined $stash->{$field->{name}}->{'required'}) { |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# restore field state from stash after validation |
52
|
|
|
|
|
|
|
|
53
|
32
|
|
|
|
|
88
|
$field->{required} = $stash->{$field->{name}}->{'required'}; |
54
|
|
|
|
|
|
|
|
55
|
32
|
|
|
|
|
119
|
delete $stash->{$field->{name}}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
32
|
50
|
|
|
|
96
|
delete $field->{toggle} if exists $field->{toggle}; |
62
|
|
|
|
|
|
|
|
63
|
32
|
|
|
|
|
76
|
return $self; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub normalize { |
68
|
|
|
|
|
|
|
|
69
|
1009
|
|
|
1009
|
0
|
2274
|
my ($self, $proto, $field, $param) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# on normalize, always remove the toggle directive |
72
|
|
|
|
|
|
|
|
73
|
1009
|
50
|
|
|
|
2457
|
delete $field->{toggle} if exists $field->{toggle}; |
74
|
|
|
|
|
|
|
|
75
|
1009
|
|
|
|
|
2058
|
return $self; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |