line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Simple::Results; |
2
|
23
|
|
|
23
|
|
33639
|
use strict; |
|
23
|
|
|
|
|
45
|
|
|
23
|
|
|
|
|
833
|
|
3
|
23
|
|
|
23
|
|
128
|
use base qw/Class::Accessor::Fast/; |
|
23
|
|
|
|
|
84
|
|
|
23
|
|
|
|
|
6544
|
|
4
|
23
|
|
|
23
|
|
19553
|
use FormValidator::Simple::Result; |
|
23
|
|
|
|
|
76
|
|
|
23
|
|
|
|
|
210
|
|
5
|
23
|
|
|
23
|
|
6193
|
use FormValidator::Simple::Exception; |
|
23
|
|
|
|
|
54
|
|
|
23
|
|
|
|
|
179
|
|
6
|
23
|
|
|
23
|
|
518
|
use FormValidator::Simple::Constants; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
1679
|
|
7
|
23
|
|
|
23
|
|
126
|
use Tie::IxHash; |
|
23
|
|
|
|
|
44
|
|
|
23
|
|
|
|
|
106
|
|
8
|
23
|
|
|
23
|
|
41019
|
use List::MoreUtils; |
|
23
|
|
|
|
|
37362
|
|
|
23
|
|
|
|
|
42254
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/_records message/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
56
|
|
|
56
|
1
|
1234
|
my $class = shift; |
14
|
56
|
|
|
|
|
180
|
my $self = bless { }, $class; |
15
|
56
|
|
|
|
|
223
|
$self->_init(@_); |
16
|
56
|
|
|
|
|
508
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init { |
20
|
56
|
|
|
56
|
|
159
|
my ($self, %args) = @_; |
21
|
56
|
|
|
|
|
137
|
my %hash = (); |
22
|
56
|
|
|
|
|
363
|
tie (%hash, 'Tie::IxHash'); |
23
|
56
|
|
|
|
|
1244
|
$self->_records(\%hash); |
24
|
|
|
|
|
|
|
|
25
|
56
|
|
|
|
|
594
|
my $messages = delete $args{messages}; |
26
|
56
|
|
|
|
|
268
|
$self->message($messages); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub messages { |
30
|
7
|
|
|
7
|
0
|
381
|
my ($self, $action) = @_; |
31
|
7
|
|
|
|
|
17
|
my @messages = (); |
32
|
7
|
|
|
|
|
119
|
my $keys = $self->error; |
33
|
7
|
|
|
|
|
71
|
foreach my $key ( @$keys ) { |
34
|
22
|
|
|
|
|
87
|
my $types = $self->error($key); |
35
|
22
|
|
|
|
|
81
|
foreach my $type ( @$types ) { |
36
|
28
|
|
|
|
|
77
|
push @messages, |
37
|
|
|
|
|
|
|
$self->message->get($action, $key, $type); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
7
|
|
|
|
|
119
|
@messages = List::MoreUtils::uniq(@messages); |
41
|
7
|
|
|
|
|
40
|
return \@messages; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub field_messages { |
45
|
2
|
|
|
2
|
0
|
3866
|
my ($self, $action) = @_; |
46
|
2
|
|
|
|
|
4
|
my $messages = {}; |
47
|
2
|
|
|
|
|
15
|
my $keys = $self->error; |
48
|
2
|
|
|
|
|
6
|
foreach my $key ( @$keys ) { |
49
|
6
|
|
|
|
|
11
|
$messages->{$key} = []; |
50
|
6
|
|
|
|
|
13
|
my $types = $self->error($key); |
51
|
6
|
|
|
|
|
18
|
foreach my $type ( @$types ) { |
52
|
7
|
|
|
|
|
15
|
my $message = $self->message->get($action, $key, $type); |
53
|
7
|
50
|
|
1
|
|
22
|
unless ( List::MoreUtils::any { $_ eq $message } @{ $messages->{$key} } ) { |
|
1
|
|
|
|
|
4
|
|
|
7
|
|
|
|
|
37
|
|
54
|
7
|
|
|
|
|
7
|
push @{ $messages->{$key} }, $message; |
|
7
|
|
|
|
|
34
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
7
|
return $messages; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub register { |
62
|
215
|
|
|
215
|
0
|
1031
|
my ($self, $name) = @_; |
63
|
215
|
|
66
|
|
|
595
|
$self->_records->{$name} |
64
|
|
|
|
|
|
|
||= FormValidator::Simple::Result->new($name); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub record { |
68
|
441
|
|
|
441
|
0
|
2745
|
my ($self, $name) = @_; |
69
|
441
|
50
|
|
|
|
1090
|
$self->register($name) |
70
|
|
|
|
|
|
|
unless exists $self->_records->{$name}; |
71
|
441
|
|
|
|
|
5220
|
return $self->_records->{$name}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub set_result { |
75
|
111
|
|
|
111
|
0
|
1283
|
my ($self, $name, $type, $result) = @_; |
76
|
111
|
|
|
|
|
276
|
$self->register($name); |
77
|
111
|
|
|
|
|
1654
|
$self->record($name)->set($type, $result); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub set_invalid { |
81
|
1
|
|
|
1
|
0
|
3
|
my ($self, $name, $type) = @_; |
82
|
1
|
50
|
33
|
|
|
7
|
unless ($name && $type) { |
83
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
84
|
|
|
|
|
|
|
qq/set_invalid needs two arguments./ |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
1
|
|
|
|
|
3
|
$self->set_result($name, $type, FALSE); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub success { |
91
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
92
|
3
|
100
|
66
|
|
|
7
|
return ($self->has_missing or $self->has_invalid) ? FALSE : TRUE; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub has_error { |
96
|
3
|
|
|
3
|
1
|
1640
|
my $self = shift; |
97
|
3
|
100
|
66
|
|
|
11
|
return ($self->has_missing or $self->has_invalid) ? TRUE : FALSE; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub has_blank { |
101
|
9
|
|
|
9
|
0
|
1634
|
my $self = shift; |
102
|
9
|
|
|
|
|
12
|
foreach my $record ( values %{ $self->_records } ) { |
|
9
|
|
|
|
|
30
|
|
103
|
12
|
100
|
|
|
|
379
|
return TRUE if $record->is_blank; |
104
|
|
|
|
|
|
|
} |
105
|
3
|
|
|
|
|
54
|
return FALSE; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
*has_missing = \&has_blank; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub has_invalid { |
111
|
7
|
|
|
7
|
1
|
15
|
my $self = shift; |
112
|
7
|
|
|
|
|
9
|
foreach my $record ( values %{ $self->_records } ) { |
|
7
|
|
|
|
|
23
|
|
113
|
13
|
100
|
|
|
|
150
|
return TRUE if $record->is_invalid; |
114
|
|
|
|
|
|
|
} |
115
|
6
|
|
|
|
|
63
|
return FALSE; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub valid { |
119
|
12
|
|
|
12
|
0
|
1951
|
my ($self, $name) = @_; |
120
|
12
|
100
|
|
|
|
34
|
if ($name) { |
121
|
7
|
50
|
|
|
|
25
|
return unless exists $self->_records->{$name}; |
122
|
7
|
100
|
|
|
|
93
|
return $self->record($name)->is_valid |
123
|
|
|
|
|
|
|
? $self->record($name)->data : FALSE; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
10
|
|
|
|
|
63
|
my %valids |
127
|
5
|
|
|
|
|
9
|
= map { ( $_->name, $_->data ) } grep { $_->is_valid } values %{ $self->_records }; |
|
14
|
|
|
|
|
211
|
|
|
5
|
|
|
|
|
17
|
|
128
|
5
|
|
|
|
|
85
|
return \%valids; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub error { |
133
|
41
|
|
|
41
|
1
|
5658
|
my ($self, $name, $constraint) = @_; |
134
|
41
|
100
|
|
|
|
167
|
if ($name) { |
135
|
31
|
100
|
|
|
|
57
|
if ($constraint) { |
136
|
1
|
50
|
|
|
|
7
|
if ($constraint eq 'NOT_BLANK') { |
137
|
1
|
50
|
|
|
|
6
|
return $self->record($name)->is_blank |
138
|
|
|
|
|
|
|
? TRUE |
139
|
|
|
|
|
|
|
: FALSE |
140
|
|
|
|
|
|
|
; |
141
|
|
|
|
|
|
|
} |
142
|
0
|
0
|
|
|
|
0
|
return $self->record($name)->is_invalid_for($constraint) |
143
|
|
|
|
|
|
|
? TRUE |
144
|
|
|
|
|
|
|
: FALSE |
145
|
|
|
|
|
|
|
; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
else { |
148
|
30
|
100
|
|
|
|
71
|
if ($self->record($name)->is_blank) { |
|
|
50
|
|
|
|
|
|
149
|
13
|
50
|
|
|
|
215
|
return wantarray ? 'NOT_BLANK' : ['NOT_BLANK']; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ($self->record($name)->is_invalid) { |
152
|
17
|
|
|
|
|
44
|
my $constraints = $self->record($name)->constraints; |
153
|
17
|
|
|
|
|
253
|
my @invalids = grep { !$constraints->{$_} } keys %$constraints; |
|
33
|
|
|
|
|
506
|
|
154
|
17
|
50
|
|
|
|
176
|
return wantarray ? @invalids : \@invalids; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
0
|
|
|
|
|
0
|
return FALSE; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
else { |
162
|
31
|
|
|
|
|
219
|
my @errors = |
163
|
10
|
100
|
|
|
|
18
|
map { $_->name } grep { $_->is_blank or $_->is_invalid } values %{ $self->_records }; |
|
31
|
|
|
|
|
619
|
|
|
10
|
|
|
|
|
42
|
|
164
|
10
|
100
|
|
|
|
101
|
return wantarray ? @errors : \@errors; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub blank { |
169
|
9
|
|
|
9
|
0
|
1582
|
my ($self, $name) = @_; |
170
|
9
|
100
|
|
|
|
30
|
if ($name) { |
171
|
5
|
100
|
|
|
|
16
|
return $self->record($name)->is_blank ? TRUE : FALSE; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else { |
174
|
|
|
|
|
|
|
my @blanks |
175
|
4
|
|
|
|
|
10
|
= map { $_->name } grep { $_->is_blank } values %{ $self->_records }; |
|
3
|
|
|
|
|
38
|
|
|
11
|
|
|
|
|
184
|
|
|
4
|
|
|
|
|
17
|
|
176
|
4
|
100
|
|
|
|
61
|
return wantarray ? @blanks : \@blanks; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
*missing = \␣ |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub invalid { |
183
|
90
|
|
|
90
|
1
|
5840
|
my ($self, $name, $constraint) = @_; |
184
|
90
|
100
|
|
|
|
291
|
if ($name) { |
185
|
87
|
100
|
|
|
|
183
|
if ($constraint) { |
186
|
4
|
100
|
|
|
|
14
|
$self->record($name)->is_invalid_for($constraint) |
187
|
|
|
|
|
|
|
? TRUE : FALSE; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
else { |
190
|
83
|
100
|
|
|
|
221
|
if ($self->record($name)->is_invalid) { |
191
|
40
|
|
|
|
|
113
|
my $constraints = $self->record($name)->constraints; |
192
|
40
|
|
|
|
|
630
|
my @invalids = grep { !$constraints->{$_} } keys %$constraints; |
|
49
|
|
|
|
|
798
|
|
193
|
40
|
50
|
|
|
|
582
|
return wantarray ? @invalids : \@invalids; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
else { |
196
|
43
|
|
|
|
|
164
|
return FALSE; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
else { |
201
|
|
|
|
|
|
|
my @invalids |
202
|
3
|
|
|
|
|
8
|
= map { $_->name } grep { $_->is_invalid } values %{ $self->_records }; |
|
3
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
121
|
|
|
3
|
|
|
|
|
15
|
|
203
|
3
|
50
|
|
|
|
37
|
return wantarray ? @invalids : \@invalids; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub clear { |
208
|
1
|
|
|
1
|
0
|
526
|
%{shift->_records} = (); |
|
1
|
|
|
|
|
5
|
|
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
212
|
|
|
|
|
|
|
__END__ |