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