line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
103118
|
use strict; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
598
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::Equal; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Constraint::Equal::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Multi-field Equality Constraint |
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
623
|
use Moose; |
|
9
|
|
|
|
|
478847
|
|
|
9
|
|
|
|
|
72
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Constraint::Others'; |
11
|
|
|
|
|
|
|
|
12
|
9
|
|
|
|
|
785
|
use HTML::FormFu::Util qw( |
13
|
|
|
|
|
|
|
DEBUG_CONSTRAINTS |
14
|
|
|
|
|
|
|
debug |
15
|
9
|
|
|
9
|
|
65580
|
); |
|
9
|
|
|
|
|
23
|
|
16
|
9
|
|
|
9
|
|
68
|
use List::Util 1.33 qw( all ); |
|
9
|
|
|
|
|
328
|
|
|
9
|
|
|
|
|
5866
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $EMPTY_STR = q{}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub process { |
21
|
35
|
|
|
35
|
0
|
102
|
my ( $self, $params ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# check when condition |
24
|
35
|
50
|
|
|
|
239
|
return if !$self->_process_when($params); |
25
|
|
|
|
|
|
|
|
26
|
35
|
|
|
|
|
1142
|
my $others = $self->others; |
27
|
35
|
50
|
|
|
|
109
|
return if !defined $others; |
28
|
|
|
|
|
|
|
|
29
|
35
|
|
|
|
|
178
|
my $value = $self->get_nested_hash_value( $params, $self->nested_name ); |
30
|
|
|
|
|
|
|
|
31
|
35
|
50
|
|
|
|
123
|
DEBUG_CONSTRAINTS && debug( VALUE => $value ); |
32
|
|
|
|
|
|
|
|
33
|
35
|
100
|
|
|
|
116
|
my @names = ref $others ? @{$others} : ($others); |
|
31
|
|
|
|
|
103
|
|
34
|
35
|
|
|
|
|
78
|
my @failed; |
35
|
|
|
|
|
|
|
my %values; |
36
|
|
|
|
|
|
|
|
37
|
35
|
|
|
|
|
308
|
for my $name (@names) { |
38
|
|
|
|
|
|
|
|
39
|
66
|
|
|
|
|
222
|
my $other_value = $self->get_nested_hash_value( $params, $name ); |
40
|
|
|
|
|
|
|
|
41
|
66
|
50
|
|
|
|
162
|
DEBUG_CONSTRAINTS && debug( NAME => $name, VALUE => $value ); |
42
|
|
|
|
|
|
|
|
43
|
66
|
|
|
|
|
184
|
my $ok = _values_eq( $value, $other_value ); |
44
|
|
|
|
|
|
|
|
45
|
66
|
100
|
|
|
|
2023
|
if ( $self->not ) { |
|
|
100
|
|
|
|
|
|
46
|
28
|
100
|
|
|
|
87
|
if ( $value eq $EMPTY_STR ) { |
|
|
100
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# no error if both values are empty and not(1) is set |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($ok) { |
51
|
6
|
|
|
|
|
18
|
push @failed, $name; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( !$ok ) { |
55
|
11
|
|
|
|
|
43
|
push @failed, $name; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
66
|
|
|
|
|
202
|
$values{$name} = $other_value; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# special case for $self->not() |
62
|
|
|
|
|
|
|
# no errors if all values are empty |
63
|
35
|
100
|
100
|
|
|
959
|
if ( $self->not |
|
|
|
100
|
|
|
|
|
64
|
|
|
|
|
|
|
&& $value eq $EMPTY_STR |
65
|
9
|
50
|
|
9
|
|
56
|
&& all { !defined || $_ eq $EMPTY_STR } values %values ) |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
|
|
17
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
33
|
100
|
|
|
|
208
|
return $self->mk_errors( |
71
|
|
|
|
|
|
|
{ pass => @failed ? 0 : 1, |
72
|
|
|
|
|
|
|
failed => \@failed, |
73
|
|
|
|
|
|
|
names => [ $self->nested_name, @names ], |
74
|
|
|
|
|
|
|
} ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _values_eq { |
78
|
71
|
|
|
71
|
|
313
|
my ( $v1, $v2 ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# the params should be coming from a CGI.pm compatible query object, |
81
|
|
|
|
|
|
|
# so the value is either a string or an arrayref of strings |
82
|
|
|
|
|
|
|
|
83
|
71
|
0
|
33
|
|
|
204
|
return 1 if !defined $v1 && !defined $v2; |
84
|
|
|
|
|
|
|
|
85
|
71
|
100
|
66
|
|
|
373
|
return if !defined $v1 || !defined $v2; |
86
|
|
|
|
|
|
|
|
87
|
69
|
100
|
66
|
|
|
339
|
if ( !ref $v1 && !ref $v2 ) { |
|
|
100
|
66
|
|
|
|
|
88
|
59
|
100
|
|
|
|
185
|
return 1 if $v1 eq $v2; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ( ( ref $v1 eq 'ARRAY' ) && ( ref $v2 eq 'ARRAY' ) ) { |
91
|
8
|
|
|
|
|
29
|
return _arrays_eq( $v1, $v2 ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
25
|
|
|
|
|
52
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _arrays_eq { |
98
|
8
|
|
|
8
|
|
17
|
my @a1 = sort @{ $_[0] }; |
|
8
|
|
|
|
|
48
|
|
99
|
8
|
|
|
|
|
19
|
my @a2 = sort @{ $_[1] }; |
|
8
|
|
|
|
|
21
|
|
100
|
|
|
|
|
|
|
|
101
|
8
|
50
|
|
|
|
27
|
return if scalar @a1 != scalar @a2; |
102
|
|
|
|
|
|
|
|
103
|
8
|
|
|
|
|
31
|
for my $i ( 0 .. $#a1 ) { |
104
|
15
|
50
|
|
|
|
46
|
return if $a1[$i] ne $a2[$i]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
8
|
|
|
|
|
27
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _localize_args { |
111
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $self->parent->label; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=encoding UTF-8 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
HTML::FormFu::Constraint::Equal - Multi-field Equality Constraint |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
version 2.07 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SYNOPSIS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
- type: Password |
137
|
|
|
|
|
|
|
name: password |
138
|
|
|
|
|
|
|
constraints: |
139
|
|
|
|
|
|
|
- type: Equal |
140
|
|
|
|
|
|
|
others: repeat_password |
141
|
|
|
|
|
|
|
- type: Password |
142
|
|
|
|
|
|
|
name: repeat_password |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 DESCRIPTION |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
All fields named in L<HTML::FormFu::Role::Constraint::Others/others> must have an equal value to the field this |
147
|
|
|
|
|
|
|
constraint is attached to. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SEE ALSO |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
152
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Constraint::Others>, L<HTML::FormFu::Constraint> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<HTML::FormFu> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 LICENSE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
163
|
|
|
|
|
|
|
the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
174
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |