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
|
109
|
|
|
109
|
|
54470
|
use strict; |
|
109
|
|
|
|
|
303
|
|
|
109
|
|
|
|
|
3118
|
|
6
|
109
|
|
|
109
|
|
606
|
use warnings; |
|
109
|
|
|
|
|
285
|
|
|
109
|
|
|
|
|
6744
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
779
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
3792
|
|
|
109
|
|
|
|
|
10918
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
862
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
311
|
|
|
109
|
|
|
|
|
837
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # 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
|
1009
|
|
|
1009
|
0
|
2598
|
my ($self, $proto, $field, $param) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# override parameter value if default exists |
29
|
|
|
|
|
|
|
|
30
|
1009
|
100
|
100
|
|
|
3256
|
if (defined $field->{default} && ! defined $param) { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @defaults = isa_arrayref($field->{default}) ? |
33
|
1
|
|
|
|
|
150
|
@{$field->{default}} : ($field->{default}) |
34
|
4
|
100
|
|
|
|
42
|
; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
43
|
my $context = $proto->stash->{'normalization.context'}; |
37
|
4
|
|
|
|
|
30
|
my $name = $field->name; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
14
|
foreach my $default (@defaults) { |
40
|
5
|
100
|
|
|
|
20
|
$default = $default->($context, $proto) if isa_coderef($default); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
100
|
|
|
|
23
|
$proto->params->add($name, @defaults == 1 ? $defaults[0] : [@defaults]); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1009
|
|
|
|
|
2607
|
return $self; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |