line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
893
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
278
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::Repeatable::Any; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Constraint::Repeatable::Any::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Ensure at least 1 of a repeated field is filled-in |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
25
|
use Moose; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
38
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
28902
|
use Scalar::Util qw( reftype ); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
282
|
|
12
|
4
|
|
|
4
|
|
27
|
use Carp qw( croak ); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
2635
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
after BUILD => sub { |
15
|
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$self->only_on_reps( [1] ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub process { |
23
|
34
|
|
|
34
|
0
|
73
|
my ( $self, $params ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
34
|
100
|
|
|
|
107
|
return unless $self->_run_this_rep; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# check when condition |
28
|
16
|
50
|
|
|
|
110
|
return if !$self->_process_when($params); |
29
|
|
|
|
|
|
|
|
30
|
16
|
|
|
|
|
54
|
my $field = $self->field; |
31
|
16
|
|
|
|
|
88
|
my $repeatable = $field->get_parent( { type => 'Repeatable' } ); |
32
|
16
|
|
|
|
|
47
|
my $pass; |
33
|
|
|
|
|
|
|
|
34
|
16
|
|
100
|
|
|
510
|
my $original_name = $field->original_name || ''; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my @fields |
37
|
46
|
|
|
|
|
188
|
= grep { $_->get_parent( { type => 'Repeatable' } ) == $repeatable } |
38
|
52
|
|
100
|
|
|
1548
|
grep { ( $_->original_name || '' ) eq $original_name } |
39
|
16
|
|
|
|
|
35
|
@{ $repeatable->get_fields }; |
|
16
|
|
|
|
|
65
|
|
40
|
|
|
|
|
|
|
|
41
|
16
|
|
|
|
|
581
|
my $increment_field_names = $repeatable->increment_field_names; |
42
|
|
|
|
|
|
|
|
43
|
16
|
|
|
|
|
72
|
for my $f (@fields) { |
44
|
28
|
|
|
|
|
49
|
my $value; |
45
|
|
|
|
|
|
|
|
46
|
28
|
100
|
|
|
|
64
|
if ($increment_field_names) { |
47
|
22
|
|
|
|
|
77
|
$value = $self->get_nested_hash_value( $params, $f->nested_name ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
6
|
|
|
|
|
15
|
$value = _find_this_field_value( $self, $f, $repeatable, $params ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
28
|
|
|
|
|
59
|
my $ok = eval { $self->constrain_value($value) }; |
|
28
|
|
|
|
|
96
|
|
54
|
|
|
|
|
|
|
|
55
|
28
|
100
|
66
|
|
|
107
|
if ( $ok && !$@ ) { |
56
|
12
|
|
|
|
|
34
|
$pass = 1; |
57
|
12
|
|
|
|
|
30
|
last; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
16
|
|
|
|
|
96
|
return $self->mk_errors( { pass => $pass, } ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _find_this_field_value { |
65
|
6
|
|
|
6
|
|
14
|
my ( $self, $field, $repeatable, $params ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
6
|
|
|
|
|
18
|
my $nested_name = $field->nested_name; |
68
|
|
|
|
|
|
|
|
69
|
6
|
|
|
|
|
24
|
my $value = $self->get_nested_hash_value( $params, $nested_name ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my @fields_with_this_name |
72
|
6
|
|
|
|
|
11
|
= @{ $repeatable->get_fields( { nested_name => $nested_name } ) }; |
|
6
|
|
|
|
|
34
|
|
73
|
|
|
|
|
|
|
|
74
|
6
|
50
|
|
|
|
21
|
if ( @fields_with_this_name > 1 ) { |
75
|
6
|
|
|
|
|
10
|
my $index; |
76
|
|
|
|
|
|
|
|
77
|
6
|
|
|
|
|
18
|
for ( my $i = 0; $i <= $#fields_with_this_name; ++$i ) { |
78
|
8
|
100
|
|
|
|
29
|
if ( $fields_with_this_name[$i] eq $field ) { |
79
|
6
|
|
|
|
|
12
|
$index = $i; |
80
|
6
|
|
|
|
|
9
|
last; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
6
|
50
|
|
|
|
15
|
croak 'did not find ourself - how can this happen?' |
85
|
|
|
|
|
|
|
if !defined $index; |
86
|
|
|
|
|
|
|
|
87
|
6
|
50
|
|
|
|
19
|
if ( reftype($value) eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
|
88
|
6
|
|
|
|
|
15
|
$value = $value->[$index]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ( $index == 0 ) { |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# keep $value |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
|
|
|
|
0
|
undef $value; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
6
|
|
|
|
|
17
|
return $value; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub constrain_value { |
103
|
28
|
|
|
28
|
0
|
70
|
my ( $self, $value ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
28
|
|
66
|
|
|
127
|
return defined $value && length $value; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _localize_args { |
109
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return |
112
|
1
|
|
33
|
|
|
5
|
$self->parent->label |
113
|
|
|
|
|
|
|
|| $self->parent->original_name |
114
|
|
|
|
|
|
|
|| $self->parent->name; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=pod |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=encoding UTF-8 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
HTML::FormFu::Constraint::Repeatable::Any - Ensure at least 1 of a repeated field is filled-in |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 VERSION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
version 2.07 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SYNOPSIS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
elements: |
138
|
|
|
|
|
|
|
- type: Repeatable |
139
|
|
|
|
|
|
|
elements: |
140
|
|
|
|
|
|
|
- name: foo |
141
|
|
|
|
|
|
|
constraints: |
142
|
|
|
|
|
|
|
- type: Repeatable::Any |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 DESCRIPTION |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Ensure at least 1 of a repeated field is filled-in. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Any error will be attached to the first repetition of the field. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This constraint doesn't honour the C<not()> value. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L<HTML::FormFu> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
165
|
|
|
|
|
|
|
the same terms as Perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
176
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |