line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
898
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
495
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::AllOrNone; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Constraint::AllOrNone::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Multi-field All or None Constraint |
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
47
|
use Moose; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
59
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Constraint::Others'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
13
|
18
|
|
|
18
|
0
|
53
|
my ( $self, $params ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# check when condition |
16
|
18
|
50
|
|
|
|
152
|
return if !$self->_process_when($params); |
17
|
|
|
|
|
|
|
|
18
|
18
|
|
|
|
|
550
|
my $others = $self->others; |
19
|
18
|
50
|
|
|
|
59
|
return if !defined $others; |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
|
|
109
|
my @names = ( $self->nested_name ); |
22
|
18
|
100
|
|
|
|
71
|
push @names, ref $others ? @{$others} : $others; |
|
11
|
|
|
|
|
69
|
|
23
|
|
|
|
|
|
|
|
24
|
18
|
|
|
|
|
36
|
my @failed; |
25
|
|
|
|
|
|
|
|
26
|
18
|
|
|
|
|
47
|
for my $name (@names) { |
27
|
54
|
|
|
|
|
182
|
my $value = $self->get_nested_hash_value( $params, $name ); |
28
|
|
|
|
|
|
|
|
29
|
54
|
|
|
|
|
91
|
my $seen = 0; |
30
|
54
|
100
|
|
|
|
127
|
if ( ref $value eq 'ARRAY' ) { |
31
|
6
|
|
|
|
|
11
|
my @errors = eval { $self->constrain_values( $value, $params ) }; |
|
6
|
|
|
|
|
36
|
|
32
|
|
|
|
|
|
|
|
33
|
6
|
50
|
33
|
|
|
42
|
if ( !@errors && !$@ ) { |
34
|
6
|
|
|
|
|
14
|
$seen = 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
48
|
|
|
|
|
83
|
my $ok = eval { $self->constrain_value($value) }; |
|
48
|
|
|
|
|
129
|
|
39
|
|
|
|
|
|
|
|
40
|
48
|
100
|
66
|
|
|
212
|
if ( $ok && !$@ ) { |
41
|
25
|
|
|
|
|
47
|
$seen = 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
54
|
100
|
|
|
|
168
|
if ( !$seen ) { |
46
|
23
|
|
|
|
|
57
|
push @failed, $name; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
18
|
100
|
100
|
|
|
104
|
my $pass = @failed && scalar @failed != scalar @names ? 0 : 1; |
51
|
|
|
|
|
|
|
|
52
|
18
|
100
|
|
|
|
160
|
return $self->mk_errors( |
53
|
|
|
|
|
|
|
{ pass => $pass, |
54
|
|
|
|
|
|
|
failed => $pass ? [] : \@failed, |
55
|
|
|
|
|
|
|
names => \@names, |
56
|
|
|
|
|
|
|
} ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub constrain_value { |
60
|
60
|
|
|
60
|
0
|
121
|
my ( $self, $value ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
60
|
100
|
100
|
|
|
230
|
return 0 if !defined $value || $value eq ''; |
63
|
|
|
|
|
|
|
|
64
|
37
|
|
|
|
|
83
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=encoding UTF-8 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
HTML::FormFu::Constraint::AllOrNone - Multi-field All or None Constraint |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
version 2.07 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
type: AllOrNone |
88
|
|
|
|
|
|
|
name: foo |
89
|
|
|
|
|
|
|
others: [bar, baz] |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Ensure that either all or none of the named fields are present. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
By default, if some but not all fields are submitted, errors are attached to |
96
|
|
|
|
|
|
|
those fields which weren't submitted. This behaviour can be changed by setting |
97
|
|
|
|
|
|
|
any of L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_base>, |
98
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_others> or |
99
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others/attach_errors_to>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This constraint doesn't honour the C<not()> value. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
106
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others>, L<HTML::FormFu::Constraint> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<HTML::FormFu> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
117
|
|
|
|
|
|
|
the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
128
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |