line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Alias Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Alias; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
51675
|
use strict; |
|
109
|
|
|
|
|
293
|
|
|
109
|
|
|
|
|
3183
|
|
6
|
109
|
|
|
109
|
|
581
|
use warnings; |
|
109
|
|
|
|
|
231
|
|
|
109
|
|
|
|
|
2974
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
554
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
243
|
|
|
109
|
|
|
|
|
10370
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
763
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
264
|
|
|
109
|
|
|
|
|
754
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 0; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'dependencies' => sub {{ |
19
|
|
|
|
|
|
|
normalization => ['name'], |
20
|
|
|
|
|
|
|
validation => ['name'] |
21
|
|
|
|
|
|
|
}}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub normalize { |
24
|
|
|
|
|
|
|
|
25
|
1009
|
|
|
1009
|
0
|
2493
|
my ($self, $proto, $field, $param) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# create a map from aliases if applicable |
28
|
|
|
|
|
|
|
|
29
|
1009
|
|
|
|
|
3491
|
$self->execute_alias_mapping($proto, $field, $param); |
30
|
|
|
|
|
|
|
|
31
|
1009
|
|
|
|
|
2281
|
return $self; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub before_validation { |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
4
|
0
|
13
|
my ($self, $proto, $field, $param) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# create a map from aliases if applicable |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
17
|
$self->execute_alias_mapping($proto, $field, $param); |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
12
|
return $self; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub execute_alias_mapping { |
48
|
|
|
|
|
|
|
|
49
|
1013
|
|
|
1013
|
0
|
2259
|
my ($self, $proto, $field, $param) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1013
|
100
|
|
|
|
2865
|
if (defined $field->{alias}) { |
52
|
|
|
|
|
|
|
|
53
|
20
|
|
|
|
|
42
|
my $name = $field->{name}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $aliases = isa_arrayref($field->{alias}) ? |
56
|
20
|
50
|
|
|
|
62
|
$field->{alias} : [$field->{alias}] |
57
|
|
|
|
|
|
|
; |
58
|
|
|
|
|
|
|
|
59
|
20
|
|
|
|
|
42
|
foreach my $alias (@{$aliases}) { |
|
20
|
|
|
|
|
49
|
|
60
|
|
|
|
|
|
|
|
61
|
20
|
100
|
|
|
|
61
|
if ($proto->params->has($alias)) { |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# rename the submitted parameter alias with the field name |
64
|
6
|
|
|
|
|
26
|
$proto->params->add($name => $proto->params->delete($alias)); |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
19
|
push @{$proto->stash->{'validation.fields'}}, $name unless |
67
|
6
|
100
|
|
|
|
15
|
grep { $name eq $_} @{$proto->stash->{'validation.fields'}} |
|
2
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
30
|
|
68
|
|
|
|
|
|
|
; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1013
|
|
|
|
|
1856
|
return $self; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |