line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widget::Constraint; |
2
|
|
|
|
|
|
|
|
3
|
88
|
|
|
88
|
|
588
|
use warnings; |
|
88
|
|
|
|
|
204
|
|
|
88
|
|
|
|
|
2595
|
|
4
|
88
|
|
|
88
|
|
539
|
use strict; |
|
88
|
|
|
|
|
178
|
|
|
88
|
|
|
|
|
2651
|
|
5
|
88
|
|
|
88
|
|
444
|
use base 'Class::Accessor::Chained::Fast'; |
|
88
|
|
|
|
|
194
|
|
|
88
|
|
|
|
|
8914
|
|
6
|
88
|
|
|
88
|
|
604
|
use HTML::Widget::Error; |
|
88
|
|
|
|
|
226
|
|
|
88
|
|
|
|
|
863
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/message names not render_errors/); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
*msg = \&message; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
HTML::Widget::Constraint - Constraint Base Class |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $c = $widget->constraint( $type, @names ); |
19
|
|
|
|
|
|
|
$c->message('Validation error.'); |
20
|
|
|
|
|
|
|
$c->names(@names); |
21
|
|
|
|
|
|
|
$c->not(1); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Constraint Base Class. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 default_message |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Arguments: $message |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Return Value: $message |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Default error message for failing constraints. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
106
|
|
|
106
|
1
|
2371
|
sub default_message {'Invalid Input'} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 init |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Arguments: $widget |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Called once when process() gets called for the first time. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
81
|
|
|
81
|
1
|
240
|
sub init { } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 javascript |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Arguments: $id |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Should return JavaScript for client side validation and the like. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
199
|
|
|
199
|
1
|
817
|
sub javascript { } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 msg |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 message |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Arguments: $message |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Contains the validation error message. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 mk_message |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Arguments: $message |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns a validation error message. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
116
|
|
66
|
116
|
1
|
1997
|
sub mk_message { return $_[0]->message || $_[0]->default_message } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 names |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Arguments: @names |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Return Value: @names |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Contains names of params to test. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 not |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Arguments: $bool |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Return Value: $bool |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Negate constraint. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 prepare |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Arguments: $widget |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Called every time process() gets called. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
270
|
|
|
270
|
1
|
547
|
sub prepare { } |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 process |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Arguments: $widget, $params, \@uploads |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Return Value: \@errors |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Validates params and returns a arrayref containing L |
112
|
|
|
|
|
|
|
objects representing failed constraints. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub process { |
117
|
141
|
|
|
141
|
1
|
320
|
my ( $self, $w, $params ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
141
|
|
|
|
|
294
|
my $results = []; |
120
|
|
|
|
|
|
|
|
121
|
141
|
|
|
|
|
230
|
for my $name ( @{ $self->names } ) { |
|
141
|
|
|
|
|
621
|
|
122
|
147
|
|
|
|
|
1107
|
my $values = $params->{$name}; |
123
|
147
|
100
|
|
|
|
556
|
my @values = ref $values eq 'ARRAY' ? @$values : ($values); |
124
|
147
|
|
|
|
|
304
|
for my $value (@values) { |
125
|
185
|
|
|
|
|
1128
|
my $result = $self->validate($value); |
126
|
185
|
100
|
|
|
|
908
|
push @$results, |
|
|
100
|
|
|
|
|
|
127
|
|
|
|
|
|
|
HTML::Widget::Error->new( |
128
|
|
|
|
|
|
|
{ name => $name, message => $self->mk_message } ) |
129
|
|
|
|
|
|
|
if $self->not ? $result : !$result; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
141
|
|
|
|
|
2137
|
return $results; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 process_js |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Arguments: $id |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns a hashref containing JavaScripts for client side validation and |
141
|
|
|
|
|
|
|
the like. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub process_js { |
146
|
161
|
|
|
161
|
1
|
344
|
my ( $self, $id ) = @_; |
147
|
161
|
|
|
|
|
200
|
my %js; |
148
|
161
|
|
|
|
|
200
|
for my $name ( @{ $self->names } ) { |
|
161
|
|
|
|
|
594
|
|
149
|
199
|
|
|
|
|
1697
|
$js{$name} = $self->javascript("$id\_$name"); |
150
|
|
|
|
|
|
|
} |
151
|
161
|
|
|
|
|
515
|
return \%js; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 render_errors |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Arguments: @names |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A list of element names for which an error should be displayed. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
If this is not set, the default behaviour is for the error to be displayed |
161
|
|
|
|
|
|
|
for all of the Constraint's named elements. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 validate |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Arguments: $value |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Return Value: $bool |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Validates a value and returns 1 or 0. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
1
|
1
|
3
|
sub validate {1} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Sebastian Riedel, C |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
182
|
|
|
|
|
|
|
the same terms as Perl itself. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |