line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::DependOn; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1071
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
285
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
23
|
use Moose; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
81
|
|
7
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Constraint::Others'; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
|
|
2135
|
use HTML::FormFu::Util qw( |
12
|
|
|
|
|
|
|
DEBUG_CONSTRAINTS |
13
|
|
|
|
|
|
|
debug |
14
|
6
|
|
|
6
|
|
25659
|
); |
|
6
|
|
|
|
|
9
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub process { |
17
|
10
|
|
|
10
|
0
|
12
|
my ( $self, $params ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# check when condition |
20
|
10
|
50
|
|
|
|
60
|
if ( !$self->_process_when($params) ) { |
21
|
0
|
0
|
|
|
|
0
|
DEBUG_CONSTRAINTS && debug('fail when() check - skipping constraint'); |
22
|
0
|
|
|
|
|
0
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
10
|
|
|
|
|
257
|
my $others = $self->others; |
26
|
10
|
50
|
|
|
|
39
|
if ( !defined $others ) { |
27
|
0
|
0
|
|
|
|
0
|
DEBUG_CONSTRAINTS && debug('no others() - skipping constraint'); |
28
|
0
|
|
|
|
|
0
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
10
|
100
|
|
|
|
27
|
my @names = ref $others ? @{$others} : ($others); |
|
6
|
|
|
|
|
20
|
|
32
|
10
|
|
|
|
|
9
|
my @failed; |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
55
|
my $value = $self->get_nested_hash_value( $params, $self->nested_name ); |
35
|
|
|
|
|
|
|
|
36
|
10
|
50
|
|
|
|
30
|
if ( !$self->constrain_value($value) ) { |
37
|
0
|
0
|
|
|
|
0
|
DEBUG_CONSTRAINTS && debug('no value - skipping constraint'); |
38
|
0
|
|
|
|
|
0
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
|
|
21
|
for my $name (@names) { |
42
|
16
|
|
|
|
|
32
|
my $value = $self->get_nested_hash_value( $params, $name ); |
43
|
|
|
|
|
|
|
|
44
|
16
|
|
|
|
|
19
|
my $ok = 0; |
45
|
|
|
|
|
|
|
|
46
|
16
|
50
|
|
|
|
32
|
if ( ref $value eq 'ARRAY' ) { |
47
|
0
|
|
|
|
|
0
|
my @err = eval { $self->constrain_values( $value, $params ) }; |
|
0
|
|
|
|
|
0
|
|
48
|
0
|
0
|
0
|
|
|
0
|
$ok = 1 if !@err && !$@; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
16
|
|
|
|
|
15
|
$ok = eval { $self->constrain_value($value) }; |
|
16
|
|
|
|
|
22
|
|
52
|
16
|
50
|
|
|
|
29
|
$ok = 0 if $@; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
16
|
100
|
|
|
|
39
|
if ( !$ok ) { |
56
|
5
|
|
|
|
|
17
|
push @failed, $name; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
10
|
100
|
|
|
|
55
|
return $self->mk_errors( { |
61
|
|
|
|
|
|
|
pass => @failed ? 0 : 1, |
62
|
|
|
|
|
|
|
failed => \@failed, |
63
|
|
|
|
|
|
|
names => [ $self->nested_name, @names ], |
64
|
|
|
|
|
|
|
} ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub constrain_value { |
68
|
26
|
|
|
26
|
0
|
30
|
my ( $self, $value ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
26
|
100
|
66
|
|
|
99
|
return 0 if !defined $value || $value eq ''; |
71
|
|
|
|
|
|
|
|
72
|
21
|
|
|
|
|
32
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _localize_args { |
76
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $self->parent->label; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
HTML::FormFu::Constraint::DependOn - Multi-field Dependency Constraint |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 2.05 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
type: DependOn |
98
|
|
|
|
|
|
|
name: foo |
99
|
|
|
|
|
|
|
others: bar |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 DESCRIPTION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
If a value is submitted for the field this constraint is attached to, then a |
104
|
|
|
|
|
|
|
value must also be submitted for all fields named in |
105
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/others>. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
By default, if any of the named fields in |
108
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/others> are missing, an error will be |
109
|
|
|
|
|
|
|
attached to each missing field. This behaviour can be changed by setting |
110
|
|
|
|
|
|
|
any of L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_base>, |
111
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_others> or |
112
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/attach_errors_to>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This constraint doesn't honour the C<not()> value. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
119
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others>, L<HTML::FormFu::Constraint> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L<HTML::FormFu> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 LICENSE |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
130
|
|
|
|
|
|
|
the same terms as Perl itself. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |