line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FillInForm::Lite; |
2
|
16
|
|
|
16
|
|
3648574
|
use 5.008_001; # 5.8.1 |
|
16
|
|
|
|
|
51
|
|
3
|
|
|
|
|
|
|
|
4
|
16
|
|
|
16
|
|
53
|
use strict; |
|
16
|
|
|
|
|
23
|
|
|
16
|
|
|
|
|
272
|
|
5
|
16
|
|
|
16
|
|
48
|
use warnings; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
509
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.14'; |
8
|
|
|
|
|
|
|
|
9
|
16
|
|
|
16
|
|
64
|
use Exporter (); |
|
16
|
|
|
|
|
14
|
|
|
16
|
|
|
|
|
594
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(fillinform); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#use Smart::Comments '####'; |
14
|
16
|
|
|
16
|
|
48
|
use Carp (); |
|
16
|
|
|
|
|
18
|
|
|
16
|
|
|
|
|
197
|
|
15
|
16
|
|
|
16
|
|
46
|
use Scalar::Util (); |
|
16
|
|
|
|
|
14
|
|
|
16
|
|
|
|
|
35515
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Regexp for HTML tags |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $form = q{[fF][oO][rR][mM]}; |
20
|
|
|
|
|
|
|
my $input = q{[iI][nN][pP][uU][tT]}; |
21
|
|
|
|
|
|
|
my $select = q{[sS][eE][lL][eE][cC][tT] }; |
22
|
|
|
|
|
|
|
my $option = q{[oO][pP][tT][iI][oO][nN] }; |
23
|
|
|
|
|
|
|
my $textarea = q{[tT][eE][xX][tT][aA][rR][eE][aA]}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $checked = q{[cC][hH][eE][cC][kK][eE][dD]}; |
26
|
|
|
|
|
|
|
my $selected = q{[sS][eE][lL][eE][cC][tT][eE][dD]}; |
27
|
|
|
|
|
|
|
my $multiple = q{[mM][uU][lL][tT][iI][pP][lL][eE]}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $id = q{[iI][dD]}; |
30
|
|
|
|
|
|
|
my $type = q{[tT][yY][pP][eE]}; |
31
|
|
|
|
|
|
|
my $name = q{[nN][aA][mM][eE]}; |
32
|
|
|
|
|
|
|
my $value = q{[vV][aA][lL][uU][eE]}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $SPACE = q{\s}; |
35
|
|
|
|
|
|
|
my $ATTR_NAME = q{[\w\-]+}; |
36
|
|
|
|
|
|
|
my $ATTR_VALUE = q{(?:" [^"]* " | ' [^']* ' | [^'"/>\s]+ | [\w\-]+ )}; |
37
|
|
|
|
|
|
|
my $ATTR = qq{(?: $SPACE+ (?: $ATTR_NAME (?: = $ATTR_VALUE )? ) )}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $FORM = qq{(?: <$form $ATTR+ $SPACE* > )}; # |
40
|
|
|
|
|
|
|
my $INPUT = qq{(?: <$input $ATTR+ $SPACE*/?> )}; # |
41
|
|
|
|
|
|
|
my $SELECT = qq{(?: <$select $ATTR+ $SPACE* > )}; # |
42
|
|
|
|
|
|
|
my $OPTION = qq{(?: <$option $ATTR* $SPACE* > )}; # |
43
|
|
|
|
|
|
|
my $TEXTAREA = qq{(?: <$textarea $ATTR+ $SPACE* > )}; # |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $END_FORM = qq{(?: $form> )}; |
46
|
|
|
|
|
|
|
my $END_SELECT = qq{(?: $select> )}; |
47
|
|
|
|
|
|
|
my $END_OPTION = qq{(?: $option> )}; |
48
|
|
|
|
|
|
|
my $END_TEXTAREA = qq{(?: $textarea> )}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $CHECKED = qq{(?: |
51
|
|
|
|
|
|
|
$checked (?: = (?: "$checked " | '$checked' | $checked ) )? |
52
|
|
|
|
|
|
|
)}; |
53
|
|
|
|
|
|
|
my $SELECTED = qq{(?: |
54
|
|
|
|
|
|
|
$selected (?: = (?: "$selected" | '$selected' | $selected ) )? |
55
|
|
|
|
|
|
|
)}; |
56
|
|
|
|
|
|
|
my $MULTIPLE = qq{(?: |
57
|
|
|
|
|
|
|
$multiple (?: = (?: "$multiple" | '$multiple' | $multiple ) )? |
58
|
|
|
|
|
|
|
)}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#my $DISABLED = q{(?: disabled = (?: "disabled" | 'disabled' | disabled ) )}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#sub _extract{ # for debugging only |
63
|
|
|
|
|
|
|
# my $s = shift; |
64
|
|
|
|
|
|
|
# my %f = (input => [], select => [], textarea => []); |
65
|
|
|
|
|
|
|
# @{$f{input}} = $s =~ m{($INPUT)}gxmsi; |
66
|
|
|
|
|
|
|
# @{$f{select}} = $s =~ m{($SELECT.*?$END_SELECT)}gxmsi; |
67
|
|
|
|
|
|
|
# @{$f{textarea}} = $s =~ m{($TEXTAREA.*?$END_TEXTAREA)}gxmsi; |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# return \%f; |
70
|
|
|
|
|
|
|
#} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub fillinform { # function interface to fill() |
74
|
5
|
100
|
|
5
|
1
|
27
|
if(@_ == 1) { |
75
|
1
|
|
|
|
|
2
|
my($data) = @_; |
76
|
1
|
|
|
|
|
3
|
my $fif = __PACKAGE__->new(); |
77
|
|
|
|
|
|
|
return sub { |
78
|
2
|
|
|
2
|
|
261
|
my($form) = @_; |
79
|
2
|
|
|
|
|
4
|
return $fif->fill(\$form, $data); |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
9
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
4
|
|
|
|
|
7
|
my($form, $data) = @_; |
84
|
4
|
|
|
|
|
20
|
return __PACKAGE__->fill(\$form, $data); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# utilities for getting HTML attributes |
89
|
|
|
|
|
|
|
sub _unquote{ |
90
|
165
|
100
|
|
165
|
|
710
|
$_[0] =~ /(['"]) (.*) \1/xms ? $2 : $_[0]; # ' for poor editors |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
sub _get_id{ |
93
|
22
|
100
|
|
22
|
|
144
|
$_[0] =~ /$SPACE $id = ($ATTR_VALUE)/xms ? _unquote($1) : undef; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
sub _get_type{ |
96
|
59
|
100
|
|
59
|
|
860
|
$_[0] =~ /$SPACE $type = ($ATTR_VALUE)/xms ? _unquote($1) : undef; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
sub _get_name{ |
99
|
104
|
50
|
|
104
|
|
1149
|
$_[0] =~ /$SPACE $name = ($ATTR_VALUE)/xms ? _unquote($1) : undef; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
sub _get_value{ |
102
|
53
|
100
|
|
53
|
|
382
|
$_[0] =~ /$SPACE $value = ($ATTR_VALUE)/xms ? _unquote($1) : undef; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#use macro |
106
|
|
|
|
|
|
|
# _unquote => \&_unquote, |
107
|
|
|
|
|
|
|
# _get_id => \&_get_id, |
108
|
|
|
|
|
|
|
# _get_type => \&_get_type, |
109
|
|
|
|
|
|
|
# _get_name => \&_get_name, |
110
|
|
|
|
|
|
|
# _get_value => \&_get_value, |
111
|
|
|
|
|
|
|
#; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub new :method{ |
114
|
19
|
|
|
19
|
1
|
1964
|
my $class = shift; |
115
|
19
|
|
|
|
|
60
|
return $class->_parse_option(@_); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _parse_option{ |
119
|
117
|
|
|
117
|
|
112
|
my $self = shift; |
120
|
|
|
|
|
|
|
|
121
|
117
|
100
|
100
|
|
|
473
|
if(ref $self and not @_){ # as instance method with no option |
122
|
63
|
|
|
|
|
87
|
return $self; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
54
|
|
|
|
|
289
|
my %context = ( |
126
|
|
|
|
|
|
|
ignore_types => { |
127
|
|
|
|
|
|
|
button => 1, |
128
|
|
|
|
|
|
|
submit => 1, |
129
|
|
|
|
|
|
|
reset => 1, |
130
|
|
|
|
|
|
|
password => 1, |
131
|
|
|
|
|
|
|
image => 1, |
132
|
|
|
|
|
|
|
file => 1, |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
escape => \&_escape_html, |
136
|
|
|
|
|
|
|
decode_entity => \&_noop, |
137
|
|
|
|
|
|
|
layer => '', |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# merge if needed |
141
|
54
|
100
|
|
|
|
122
|
if(ref $self){ |
142
|
18
|
|
|
|
|
16
|
while(my($key, $val) = each %{$self}){ |
|
111
|
|
|
|
|
202
|
|
143
|
93
|
100
|
|
|
|
154
|
$context{$key} = ref($val) eq 'HASH' ? { %{$val} } : $val; |
|
30
|
|
|
|
|
89
|
|
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# parse options |
148
|
54
|
|
|
|
|
187
|
while(my($opt, $val) = splice @_, 0, 2){ |
149
|
31
|
50
|
|
|
|
51
|
next unless defined $val; |
150
|
|
|
|
|
|
|
|
151
|
31
|
50
|
33
|
|
|
171
|
if( $opt eq 'ignore_fields' |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
152
|
|
|
|
|
|
|
or $opt eq 'disable_fields' ){ |
153
|
0
|
|
0
|
|
|
0
|
@{ $context{$opt} ||= {} }{ @{$val} } |
|
0
|
|
|
|
|
0
|
|
154
|
0
|
|
|
|
|
0
|
= (1) x @{$val}; |
|
0
|
|
|
|
|
0
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif($opt eq 'fill_password'){ |
157
|
0
|
|
|
|
|
0
|
$context{ignore_types}{password} = !$val; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
elsif($opt eq 'target'){ |
160
|
21
|
|
|
|
|
56
|
$context{target} = $val; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
elsif($opt eq 'escape'){ |
163
|
0
|
0
|
|
|
|
0
|
if($val){ |
164
|
0
|
0
|
|
|
|
0
|
$context{escape} = ref($val) eq 'CODE' |
165
|
|
|
|
|
|
|
? $val |
166
|
|
|
|
|
|
|
: \&_escape_html; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
else{ |
169
|
0
|
|
|
|
|
0
|
$context{escape} = \&_noop; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
elsif($opt eq 'layer'){ |
173
|
3
|
|
|
|
|
7
|
$context{layer} = $val; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
elsif($opt eq 'decode_entity'){ |
176
|
5
|
100
|
|
|
|
6
|
if($val){ |
177
|
4
|
100
|
|
|
|
13
|
$context{decode_entity} = ref($val) eq 'CODE' |
178
|
|
|
|
|
|
|
? $val |
179
|
|
|
|
|
|
|
: \&_decode_entity; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
else{ |
182
|
1
|
|
|
|
|
4
|
$context{decode_entity} = \&_noop; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
else{ |
186
|
2
|
|
|
|
|
277
|
Carp::croak("Unknown option '$opt' supplied"); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
52
|
|
66
|
|
|
231
|
return bless \%context => ref($self) || $self; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub fill :method{ |
194
|
100
|
|
|
100
|
1
|
11943
|
my($self, $src, $q, @opt) = @_; |
195
|
|
|
|
|
|
|
|
196
|
100
|
100
|
|
|
|
337
|
defined $src or Carp::croak('No source supplied'); |
197
|
99
|
100
|
|
|
|
242
|
defined $q or Carp::croak('No data supplied'); |
198
|
|
|
|
|
|
|
|
199
|
98
|
|
|
|
|
153
|
my $context = $self->_parse_option(@opt); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
### $context |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# HTML source to a scalar |
204
|
97
|
|
|
|
|
123
|
my $content; |
205
|
97
|
100
|
|
|
|
190
|
if(ref($src) eq 'SCALAR'){ |
|
|
50
|
|
|
|
|
|
206
|
89
|
|
|
|
|
58
|
$content = ${$src}; # copy |
|
89
|
|
|
|
|
124
|
|
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
elsif(ref($src) eq 'ARRAY'){ |
209
|
0
|
|
|
|
|
0
|
$content = join q{}, @{$src}; |
|
0
|
|
|
|
|
0
|
|
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
else{ |
212
|
8
|
|
|
|
|
20
|
my $is_fh = Scalar::Util::openhandle($src); |
213
|
|
|
|
|
|
|
|
214
|
8
|
100
|
66
|
|
|
34
|
if($is_fh or !ref($src)) { |
215
|
6
|
50
|
|
|
|
9
|
if(!$is_fh){ |
216
|
6
|
100
|
|
|
|
298
|
open my($in), '<'.$context->{layer}, $src |
217
|
|
|
|
|
|
|
or Carp::croak("Cannot open '$src': $!"); |
218
|
5
|
|
|
|
|
101
|
$src = $in; |
219
|
|
|
|
|
|
|
} |
220
|
5
|
|
|
|
|
13
|
local $/; |
221
|
5
|
|
|
|
|
95
|
$content = readline($src); # slurp |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
else { |
224
|
2
|
|
|
|
|
3
|
$content = ${$src}; |
|
2
|
|
|
|
|
16
|
|
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# if $content is utf8-flagged, params should be utf8-encoded |
229
|
95
|
|
|
|
|
273
|
local $context->{utf8} = utf8::is_utf8($content); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# param object converted from data or object |
232
|
95
|
|
|
|
|
161
|
local $context->{data} = _to_form_object($q); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# param storage for multi-text fields |
235
|
90
|
|
|
|
|
128
|
local $context->{params} = {}; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Fill in contents |
238
|
90
|
100
|
|
|
|
135
|
if(defined $context->{target}){ |
239
|
|
|
|
|
|
|
|
240
|
21
|
|
|
|
|
417
|
$content =~ s{ ($FORM) (.*?) ($END_FORM) } |
241
|
|
|
|
|
|
|
{ |
242
|
22
|
|
|
|
|
55
|
my($beg, $content, $end) = ($1, $2, $3); |
243
|
|
|
|
|
|
|
|
244
|
22
|
|
|
|
|
27
|
my $id = _get_id($beg); |
245
|
22
|
100
|
100
|
|
|
104
|
(defined($id) and $context->{target} eq $id) |
246
|
|
|
|
|
|
|
? $beg . _fill($context, $content) . $end |
247
|
|
|
|
|
|
|
: $beg . $content . $end |
248
|
|
|
|
|
|
|
}gexms; |
249
|
|
|
|
|
|
|
|
250
|
21
|
|
|
|
|
192
|
return $content; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
else{ |
253
|
69
|
|
|
|
|
97
|
return _fill($context, $content); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub _fill{ |
259
|
80
|
|
|
80
|
|
83
|
my($context, $content) = @_; |
260
|
80
|
|
|
|
|
1755
|
$content =~ s{($INPUT)} |
261
|
59
|
|
|
|
|
109
|
{ _fill_input($context, $1) }gexms; |
262
|
|
|
|
|
|
|
|
263
|
80
|
|
|
|
|
1366
|
$content =~ s{($SELECT) (.*?) ($END_SELECT) } |
264
|
29
|
|
|
|
|
45
|
{ $1 . _fill_select($context, $1, $2) . $3 }gexms; |
265
|
|
|
|
|
|
|
|
266
|
80
|
|
|
|
|
1707
|
$content =~ s{($TEXTAREA) (.*?) ($END_TEXTAREA) } |
267
|
16
|
|
|
|
|
27
|
{ $1 . _fill_textarea($context, $1, $2) . $3 }gexms; |
268
|
|
|
|
|
|
|
|
269
|
80
|
|
|
|
|
740
|
return $content; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub _fill_input{ |
274
|
59
|
|
|
59
|
|
95
|
my($context, $tag) = @_; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
### $tag |
277
|
|
|
|
|
|
|
|
278
|
59
|
|
100
|
|
|
77
|
my $type = _get_type($tag) || 'text'; |
279
|
59
|
50
|
|
|
|
128
|
if($context->{ignore_types}{ $type }){ |
280
|
0
|
|
|
|
|
0
|
return $tag; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
59
|
100
|
|
|
|
74
|
my $values_ref = $context->_get_param( _get_name($tag) ) |
284
|
|
|
|
|
|
|
or return $tag; |
285
|
|
|
|
|
|
|
|
286
|
50
|
100
|
100
|
|
|
179
|
if($type eq 'checkbox' or $type eq 'radio'){ |
287
|
5
|
|
|
|
|
6
|
my $value = _get_value($tag); |
288
|
|
|
|
|
|
|
|
289
|
5
|
50
|
|
|
|
8
|
if(not defined $value){ |
290
|
0
|
|
|
|
|
0
|
$value = 'on'; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
else{ |
293
|
5
|
|
|
|
|
7
|
$value = $context->{decode_entity}->($value); |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
5
|
50
|
|
|
|
2
|
if(grep { $value eq $_ } @{$values_ref}){ |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
6
|
|
297
|
5
|
50
|
|
|
|
109
|
$tag =~ /$CHECKED/xms |
298
|
|
|
|
|
|
|
or $tag =~ s{$SPACE* (/?) > \z} |
299
|
|
|
|
|
|
|
{ checked="checked" $1>}xms; |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
else{ |
302
|
0
|
|
|
|
|
0
|
$tag =~ s/$SPACE+$CHECKED//gxms; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
else{ |
306
|
45
|
|
|
|
|
40
|
my $new_value = $context->{escape}->(shift @{$values_ref}); |
|
45
|
|
|
|
|
84
|
|
307
|
|
|
|
|
|
|
|
308
|
45
|
100
|
|
|
|
906
|
$tag =~ s{$value = $ATTR_VALUE}{value="$new_value"}xms |
309
|
|
|
|
|
|
|
or $tag =~ s{$SPACE* (/?) > \z} |
310
|
|
|
|
|
|
|
{ value="$new_value" $1>}xms; |
311
|
|
|
|
|
|
|
} |
312
|
50
|
|
|
|
|
165
|
return $tag; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
sub _fill_select{ |
315
|
29
|
|
|
29
|
|
57
|
my($context, $tag, $content) = @_; |
316
|
|
|
|
|
|
|
|
317
|
29
|
100
|
|
|
|
35
|
my $values_ref = $context->_get_param( _get_name($tag) ) |
318
|
|
|
|
|
|
|
or return $content; |
319
|
|
|
|
|
|
|
|
320
|
28
|
100
|
|
|
|
236
|
if($tag !~ /$MULTIPLE/oxms){ |
321
|
23
|
|
|
|
|
15
|
$values_ref = [ shift @{ $values_ref } ]; # in select-one |
|
23
|
|
|
|
|
39
|
|
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
28
|
|
|
|
|
441
|
$content =~ s{($OPTION) (.*?) ($END_OPTION)} |
325
|
48
|
|
|
|
|
64
|
{ _fill_option($context, $values_ref, $1, $2) . $2 . $3 }gexms; |
326
|
28
|
|
|
|
|
108
|
return $content; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
sub _fill_option{ |
329
|
48
|
|
|
48
|
|
70
|
my($context, $values_ref, $tag, $content) = @_; |
330
|
|
|
|
|
|
|
|
331
|
48
|
|
|
|
|
51
|
my $value = _get_value($tag); |
332
|
48
|
100
|
|
|
|
77
|
unless( defined $value ){ |
333
|
26
|
|
|
|
|
22
|
$value = $content; |
334
|
26
|
|
|
|
|
69
|
$value =~ s{\A $SPACE+ } {}xms; |
335
|
26
|
|
|
|
|
46
|
$value =~ s{ $SPACE{2,}}{ }xms; |
336
|
26
|
|
|
|
|
47
|
$value =~ s{ $SPACE+ \z} {}xms; |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
48
|
|
|
|
|
63
|
$value = $context->{decode_entity}->($value); |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
### @_ |
342
|
48
|
100
|
|
|
|
39
|
if(grep{ $value eq $_ } @{$values_ref}){ |
|
62
|
|
|
|
|
108
|
|
|
48
|
|
|
|
|
47
|
|
343
|
31
|
100
|
|
|
|
340
|
$tag =~ /$SELECTED/oxms |
344
|
|
|
|
|
|
|
or $tag =~ s{ $SPACE* > \z} |
345
|
|
|
|
|
|
|
{ selected="selected">}xms; |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
else{ |
348
|
17
|
|
|
|
|
253
|
$tag =~ s/$SPACE+$SELECTED//gxms; |
349
|
|
|
|
|
|
|
} |
350
|
48
|
|
|
|
|
202
|
return $tag; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
sub _fill_textarea{ |
354
|
16
|
|
|
16
|
|
37
|
my($context, $tag, $content) = @_; |
355
|
|
|
|
|
|
|
|
356
|
16
|
100
|
|
|
|
19
|
my $values_ref = $context->_get_param( _get_name($tag) ) |
357
|
|
|
|
|
|
|
or return $content; |
358
|
|
|
|
|
|
|
|
359
|
13
|
|
|
|
|
14
|
return $context->{escape}->(shift @{$values_ref}); |
|
13
|
|
|
|
|
20
|
|
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
# utilities |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
sub _get_param{ |
365
|
104
|
|
|
104
|
|
108
|
my($context, $name) = @_; |
366
|
|
|
|
|
|
|
|
367
|
104
|
50
|
33
|
|
|
348
|
return if not defined $name or $context->{ignore_fields}{$name}; |
368
|
|
|
|
|
|
|
|
369
|
104
|
|
|
|
|
106
|
my $ref = $context->{params}{$name}; |
370
|
|
|
|
|
|
|
|
371
|
104
|
100
|
|
|
|
146
|
if(not defined $ref){ |
372
|
|
|
|
|
|
|
$ref = $context->{params}{$name} |
373
|
96
|
|
|
|
|
150
|
= [ $context->{data}->param($name) ]; |
374
|
|
|
|
|
|
|
|
375
|
96
|
100
|
|
|
|
173
|
if($context->{utf8}){ |
376
|
13
|
|
|
|
|
9
|
for my $datum( @{$ref} ){ |
|
13
|
|
|
|
|
22
|
|
377
|
10
|
100
|
|
|
|
31
|
utf8::decode($datum) unless utf8::is_utf8($datum); |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
104
|
100
|
|
|
|
64
|
return @{$ref} ? $ref : undef; |
|
104
|
|
|
|
|
302
|
|
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub _noop{ |
386
|
41
|
|
|
41
|
|
42
|
return $_[0]; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
sub _escape_html{ |
389
|
58
|
|
|
58
|
|
52
|
my $s = shift; |
390
|
|
|
|
|
|
|
# return '' unless defined $s; |
391
|
|
|
|
|
|
|
|
392
|
58
|
|
|
|
|
77
|
$s =~ s/&/&/g; |
393
|
58
|
|
|
|
|
51
|
$s =~ s/</g; |
394
|
58
|
|
|
|
|
50
|
$s =~ s/>/>/g; |
395
|
58
|
|
|
|
|
56
|
$s =~ s/"/"/g; # " for poor editors |
396
|
58
|
|
|
|
|
102
|
return $s; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub _decode_entity{ |
401
|
11
|
|
|
11
|
|
13
|
my $s = shift; |
402
|
|
|
|
|
|
|
|
403
|
11
|
|
|
|
|
5
|
our %entity2char; |
404
|
11
|
100
|
|
|
|
36
|
unless(%entity2char){ |
405
|
|
|
|
|
|
|
# load the HTML entity data |
406
|
1
|
|
|
|
|
3
|
local $/ = "__END__\n"; |
407
|
1
|
|
|
|
|
3
|
local($@, $!); |
408
|
1
|
50
|
|
|
|
36
|
open my $data_in, '<', __FILE__ or die $!; # should be success |
409
|
1
|
|
|
|
|
44
|
readline $data_in; # discard the first segment |
410
|
1
|
50
|
|
|
|
657
|
eval scalar readline($data_in) or die $@; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
11
|
100
|
|
|
|
30
|
$s =~ s{&(\w+);}{ $entity2char{$1} || "&$1;" }egxms; |
|
11
|
|
|
|
|
38
|
|
414
|
|
|
|
|
|
|
|
415
|
11
|
|
|
|
|
20
|
$s =~ s{&\#(\d+) ;}{ chr $1 }egxms; |
|
8
|
|
|
|
|
24
|
|
416
|
11
|
|
|
|
|
11
|
$s =~ s{&\#x([0-9a-fA-F]+);}{ chr hex $1 }egxms; |
|
2
|
|
|
|
|
6
|
|
417
|
11
|
|
|
|
|
20
|
return $s; |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
#sub _disable{ |
421
|
|
|
|
|
|
|
# my $context = shift; |
422
|
|
|
|
|
|
|
# my $name = shift; |
423
|
|
|
|
|
|
|
# |
424
|
|
|
|
|
|
|
# if($context->{disable_fields}{$name}){ |
425
|
|
|
|
|
|
|
# $_[0] =~ /$DISABLED/xmsi |
426
|
|
|
|
|
|
|
# or $_[0] =~ s{$SPACE* /? > \z} |
427
|
|
|
|
|
|
|
# { disabled="disabled" />}xmsi; |
428
|
|
|
|
|
|
|
# } |
429
|
|
|
|
|
|
|
# return; |
430
|
|
|
|
|
|
|
#} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
sub _to_form_object{ |
433
|
97
|
|
|
97
|
|
86
|
my($ref) = @_; |
434
|
|
|
|
|
|
|
|
435
|
97
|
|
|
|
|
80
|
my $wrapper; |
436
|
|
|
|
|
|
|
my $type; |
437
|
|
|
|
|
|
|
|
438
|
97
|
100
|
|
|
|
297
|
if(!Scalar::Util::blessed($ref)){ |
|
|
50
|
|
|
|
|
|
439
|
94
|
|
|
|
|
107
|
$type = ref $ref; |
440
|
94
|
100
|
|
|
|
138
|
if($type eq 'HASH'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
441
|
88
|
|
|
|
|
82
|
$wrapper = {}; |
442
|
88
|
|
|
|
|
140
|
@{$wrapper}{ keys %{$ref} } |
|
88
|
|
|
|
|
104
|
|
443
|
|
|
|
|
|
|
= map{ |
444
|
93
|
100
|
|
|
|
265
|
ref($_) eq 'ARRAY' ? $_ |
|
|
100
|
|
|
|
|
|
445
|
|
|
|
|
|
|
: defined($_) ? [$_] |
446
|
|
|
|
|
|
|
: [ ]; |
447
|
88
|
|
|
|
|
75
|
} values %{$ref}; |
|
88
|
|
|
|
|
178
|
|
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
elsif($type eq 'ARRAY'){ |
450
|
1
|
|
|
|
|
2
|
$wrapper = []; |
451
|
1
|
|
|
|
|
2
|
@{$wrapper} = map{ _to_form_object($_) } @{$ref}; |
|
1
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
elsif($type eq 'CODE'){ |
454
|
0
|
|
|
|
|
0
|
$wrapper = \$ref; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
else{ |
457
|
5
|
|
|
|
|
536
|
Carp::croak("Cannot use '$ref' as form data"); |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
elsif($ref->can('param')){ # a request object like CGI.pm |
461
|
0
|
|
|
|
|
0
|
return $ref; |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
else{ |
464
|
|
|
|
|
|
|
# any object is ok |
465
|
3
|
|
|
|
|
4
|
$wrapper = \$ref; |
466
|
3
|
|
|
|
|
2
|
$type = 'Object'; |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
92
|
|
|
|
|
328
|
return bless $wrapper => __PACKAGE__ . q{::} . $type; |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
sub HTML::FillInForm::Lite::HASH::param{ |
472
|
82
|
|
|
82
|
|
68
|
my($hash_ref, $key) = @_; |
473
|
|
|
|
|
|
|
|
474
|
82
|
100
|
|
|
|
200
|
my $value = $hash_ref->{$key} or return; |
475
|
|
|
|
|
|
|
|
476
|
77
|
|
|
|
|
55
|
return @{ $value }; |
|
77
|
|
|
|
|
202
|
|
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
sub HTML::FillInForm::Lite::ARRAY::param{ |
480
|
1
|
|
|
1
|
|
2
|
my($ary_ref, $key) = @_; |
481
|
|
|
|
|
|
|
|
482
|
1
|
|
|
|
|
2
|
return map{ $_->param($key) } @{$ary_ref}; |
|
2
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
sub HTML::FillInForm::Lite::CODE::param{ |
486
|
0
|
|
|
0
|
|
0
|
my($ref_to_code_ref, $key) = @_; |
487
|
|
|
|
|
|
|
|
488
|
0
|
|
|
|
|
0
|
return ${$ref_to_code_ref}->($key); |
|
0
|
|
|
|
|
0
|
|
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
sub HTML::FillInForm::Lite::Object::param{ |
491
|
15
|
|
|
15
|
|
15
|
my($ref_to_object, $key) = @_; |
492
|
15
|
100
|
|
|
|
10
|
my $method = ${$ref_to_object}->can($key) or return; |
|
15
|
|
|
|
|
51
|
|
493
|
13
|
|
|
|
|
12
|
my(@values) = ${$ref_to_object}->$method(); |
|
13
|
|
|
|
|
151
|
|
494
|
|
|
|
|
|
|
|
495
|
13
|
100
|
100
|
|
|
105
|
return @values == 1 && !defined($values[0]) ? () : @values; |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
1; |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
__END__ |