line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::GUI::input; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
59
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
420
|
|
4
|
10
|
|
|
10
|
|
54
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
443
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
HTML::GUI::input - Create and control a input input for webapp |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.01 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
10
|
|
|
10
|
|
3546
|
use HTML::GUI::widget; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw(HTML::GUI::widget); |
21
|
|
|
|
|
|
|
use HTML::GUI::log::eventList; |
22
|
|
|
|
|
|
|
use HTML::GUI::log::error; |
23
|
|
|
|
|
|
|
use Log::Log4perl qw(:easy); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 INPUT |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The input widget is the specialisation of the widget class for all user inputs (text, checkbox, combo ...). |
28
|
|
|
|
|
|
|
It enforces all the specific functions of the use input (for example : implement the validate() function to check id the submitted value is OK). |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 PUBLIC ATTRIBUTES |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head3 new |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Parameters : |
49
|
|
|
|
|
|
|
params : widget definition |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
my($class, |
56
|
|
|
|
|
|
|
$params, # widget : |
57
|
|
|
|
|
|
|
) = @_; |
58
|
|
|
|
|
|
|
#each input MUST have an id |
59
|
|
|
|
|
|
|
return undef unless defined $params->{id}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $this = $class->SUPER::new($params); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
bless($this, $class); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head3 setValue |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Parameters : |
72
|
|
|
|
|
|
|
The new value of the widget value |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Return : |
75
|
|
|
|
|
|
|
nothing |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Description : |
78
|
|
|
|
|
|
|
set the value of the widget with $newvalue. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub setValue |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
my($self,$newValue) = @_; |
85
|
|
|
|
|
|
|
$self->{value}=$newValue; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head3 getValue |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Parameters : |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Return : |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Description : |
98
|
|
|
|
|
|
|
return the current value of the widget. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub getValue |
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
my($self) = @_; |
105
|
|
|
|
|
|
|
return $self->{value}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=pod |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head3 getValueHash |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Description : |
113
|
|
|
|
|
|
|
return a hash containing the input id and value |
114
|
|
|
|
|
|
|
Return : |
115
|
|
|
|
|
|
|
a ref to a hash containing ( widgetId => widgetValue) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub getValueHash |
120
|
|
|
|
|
|
|
{ |
121
|
|
|
|
|
|
|
my($self) = @_; |
122
|
|
|
|
|
|
|
return {$self->getId() => $self->getValue()}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 setValueFromParams |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Parameters : |
130
|
|
|
|
|
|
|
-params : a hash ref |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Description : |
133
|
|
|
|
|
|
|
look for a value coresponding to the widget in $params hash; |
134
|
|
|
|
|
|
|
if it is the case,set the objet value with this one |
135
|
|
|
|
|
|
|
For more elaborate objects, the functions is specialised. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub setValueFromParams |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
my($self,$params) = @_; |
142
|
|
|
|
|
|
|
if (defined $params->{$self->{id}} ){ |
143
|
|
|
|
|
|
|
$self->setValue($params->{$self->{id}}); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=pod |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head3 validate |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Return : |
153
|
|
|
|
|
|
|
1 if all constraints are OK; |
154
|
|
|
|
|
|
|
0 if one or more constraint are broken |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub validate |
159
|
|
|
|
|
|
|
{ |
160
|
|
|
|
|
|
|
my($self) = @_; |
161
|
|
|
|
|
|
|
my $value = $self->getValue(); |
162
|
|
|
|
|
|
|
my $failedName = ''; |
163
|
|
|
|
|
|
|
my $status=1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
foreach my $constraint (@{$self->{constraints}}){ |
166
|
|
|
|
|
|
|
$failedName=''; |
167
|
|
|
|
|
|
|
SWITCH: { |
168
|
|
|
|
|
|
|
if ($constraint =~ /required/ && $value =~ /^\s*\t*$/){ |
169
|
|
|
|
|
|
|
$failedName = 'required'; |
170
|
|
|
|
|
|
|
last SWITCH; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
if ($constraint =~ /integer/ && $value ne '' && $value !~ /^\d*$/){ |
173
|
|
|
|
|
|
|
$failedName = 'integer'; |
174
|
|
|
|
|
|
|
last SWITCH; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
if ($failedName){ |
178
|
|
|
|
|
|
|
$status =0; |
179
|
|
|
|
|
|
|
my $constrInfo = {widgetLabel => $self->getLabel(), |
180
|
|
|
|
|
|
|
'constraint-name' => $failedName}; |
181
|
|
|
|
|
|
|
$self->error({ visibility => 'pub', |
182
|
|
|
|
|
|
|
'error-type'=>'constraint', |
183
|
|
|
|
|
|
|
'constraint-info' => $constrInfo, |
184
|
|
|
|
|
|
|
}); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
return $status; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=pod |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head3 error |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Parameters : |
195
|
|
|
|
|
|
|
type : string : Visibility of the error (pub/priv) |
196
|
|
|
|
|
|
|
params : hashref : params of the error |
197
|
|
|
|
|
|
|
Description : |
198
|
|
|
|
|
|
|
record one error in the current objet |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub error |
203
|
|
|
|
|
|
|
{ |
204
|
|
|
|
|
|
|
my($self, |
205
|
|
|
|
|
|
|
$params, # hashref : params of the error |
206
|
|
|
|
|
|
|
) = @_; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
my %errorParams = (); |
209
|
|
|
|
|
|
|
foreach my $paramName qw/visibility error-type constraint-info message/{ |
210
|
|
|
|
|
|
|
if (exists $params->{$paramName}){ |
211
|
|
|
|
|
|
|
$errorParams{$paramName} = $params->{$paramName}; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
$errorParams{widgetSrc} = $self; |
215
|
|
|
|
|
|
|
my $errorEvent = HTML::GUI::log::error->new(\%errorParams); |
216
|
|
|
|
|
|
|
if (!$errorEvent){ |
217
|
|
|
|
|
|
|
$self->SUPER::error({ |
218
|
|
|
|
|
|
|
visibility => 'pub', |
219
|
|
|
|
|
|
|
'error-type' => 'business', |
220
|
|
|
|
|
|
|
'message' => $params->{message}, |
221
|
|
|
|
|
|
|
}); |
222
|
|
|
|
|
|
|
return ; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
my $eventList = HTML::GUI::log::eventList::getCurrentEventList(); |
225
|
|
|
|
|
|
|
$eventList->addEvent($errorEvent); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=pod |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head3 getHtml |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Description : |
233
|
|
|
|
|
|
|
Return the html of the widget. It can be directly inserted into a screen |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub getHtml{ |
238
|
|
|
|
|
|
|
my ($self)= @_; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
return $self->getHtmlTag("p",{class=>("float")}, |
241
|
|
|
|
|
|
|
$self->getLabelHtml() |
242
|
|
|
|
|
|
|
.$self->getNudeHtml() |
243
|
|
|
|
|
|
|
); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 AUTHOR |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Jean-Christian Hassler, C<< >> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 BUGS |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
253
|
|
|
|
|
|
|
C, or through the web interface at |
254
|
|
|
|
|
|
|
L. |
255
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
256
|
|
|
|
|
|
|
your bug as I make changes. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 SUPPORT |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
perldoc HTML::GUI::widget |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
You can also look for information at: |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=over 4 |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
L |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item * CPAN Ratings |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
L |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
L |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=item * Search CPAN |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
L |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=back |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Copyright 2007 Jean-Christian Hassler, all rights reserved. |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
293
|
|
|
|
|
|
|
under the same terms as Perl itself. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
1; # End of HTML::GUI::input |