line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: DependsOn Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::DependsOn; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
53418
|
use strict; |
|
109
|
|
|
|
|
301
|
|
|
109
|
|
|
|
|
3321
|
|
6
|
109
|
|
|
109
|
|
705
|
use warnings; |
|
109
|
|
|
|
|
273
|
|
|
109
|
|
|
|
|
3102
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
634
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
284
|
|
|
109
|
|
|
|
|
10809
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
802
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
316
|
|
|
109
|
|
|
|
|
740
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 1; |
18
|
|
|
|
|
|
|
has 'message' => '%s requires %s'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub validate { |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
0
|
9
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
10
|
my ($proto, $field, $param) = @_; |
25
|
|
|
|
|
|
|
|
26
|
4
|
100
|
66
|
|
|
37
|
if (defined $field->{depends_on} && defined $param) { |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
8
|
my $specification = $field->{depends_on}; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
33
|
|
|
20
|
if ($field->{required} || $param) { |
31
|
|
|
|
|
|
|
|
32
|
3
|
100
|
|
|
|
12
|
my $dependents = isa_arrayref($specification) ? |
33
|
|
|
|
|
|
|
$specification : [$specification] |
34
|
|
|
|
|
|
|
; |
35
|
|
|
|
|
|
|
|
36
|
3
|
50
|
|
|
|
6
|
if (@{$dependents}) { |
|
3
|
|
|
|
|
12
|
|
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
9
|
my @required_fields = (); |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
8
|
foreach my $dependent (@{$dependents}) { |
|
3
|
|
|
|
|
9
|
|
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
11
|
my $field = $proto->fields->get($dependent); |
43
|
|
|
|
|
|
|
|
44
|
3
|
100
|
33
|
|
|
8
|
push @required_fields, $field->label || $field->name |
45
|
|
|
|
|
|
|
unless $proto->params->has($dependent) |
46
|
|
|
|
|
|
|
; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
3
|
100
|
|
|
|
15
|
if (my @r = @required_fields) { |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
33
|
|
|
10
|
my$list=(join(' and ',join(', ',@r[0..$#r-1])||(),$r[-1])); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
12
|
$self->error(@_, $list); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
14
|
return $self; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |