line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Default Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Default; |
4
|
|
|
|
|
|
|
|
5
|
108
|
|
|
108
|
|
69364
|
use strict; |
|
108
|
|
|
|
|
200
|
|
|
108
|
|
|
|
|
2811
|
|
6
|
108
|
|
|
108
|
|
529
|
use warnings; |
|
108
|
|
|
|
|
210
|
|
|
108
|
|
|
|
|
2829
|
|
7
|
|
|
|
|
|
|
|
8
|
108
|
|
|
108
|
|
504
|
use base 'Validation::Class::Directive'; |
|
108
|
|
|
|
|
183
|
|
|
108
|
|
|
|
|
7556
|
|
9
|
|
|
|
|
|
|
|
10
|
108
|
|
|
108
|
|
574
|
use Validation::Class::Util; |
|
108
|
|
|
|
|
210
|
|
|
108
|
|
|
|
|
747
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900057'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 1; |
18
|
|
|
|
|
|
|
has 'dependencies' => sub {{ |
19
|
|
|
|
|
|
|
normalization => ['filters', 'readonly'], |
20
|
|
|
|
|
|
|
# note: default-values are only handled during normalization now |
21
|
|
|
|
|
|
|
# validation => ['multiples', 'value'] |
22
|
|
|
|
|
|
|
}}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub normalize { |
25
|
|
|
|
|
|
|
|
26
|
1002
|
|
|
1002
|
0
|
1861
|
my ($self, $proto, $field, $param) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# override parameter value if default exists |
29
|
|
|
|
|
|
|
|
30
|
1002
|
100
|
100
|
|
|
3418
|
if (defined $field->{default} && ! defined $param) { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @defaults = isa_arrayref($field->{default}) ? |
33
|
1
|
|
|
|
|
4
|
@{$field->{default}} : ($field->{default}) |
34
|
4
|
100
|
|
|
|
17
|
; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
14
|
my $context = $proto->stash->{'normalization.context'}; |
37
|
4
|
|
|
|
|
12
|
my $name = $field->name; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
10
|
foreach my $default (@defaults) { |
40
|
5
|
100
|
|
|
|
31
|
$default = $default->($context, $proto) if isa_coderef($default); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
100
|
|
|
|
19
|
$proto->params->add($name, @defaults == 1 ? $defaults[0] : [@defaults]); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1002
|
|
|
|
|
2875
|
return $self; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |