line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Shakan::Widgets::Simple; |
2
|
23
|
|
|
23
|
|
133
|
use strict; |
|
23
|
|
|
|
|
46
|
|
|
23
|
|
|
|
|
547
|
|
3
|
23
|
|
|
23
|
|
147
|
use warnings; |
|
23
|
|
|
|
|
44
|
|
|
23
|
|
|
|
|
458
|
|
4
|
23
|
|
|
23
|
|
115
|
use HTML::Escape; |
|
23
|
|
|
|
|
46
|
|
|
23
|
|
|
|
|
1033
|
|
5
|
23
|
|
|
23
|
|
9435
|
use List::MoreUtils qw/zip/; |
|
23
|
|
|
|
|
151482
|
|
|
23
|
|
|
|
|
206
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub render { |
8
|
34
|
|
|
34
|
0
|
82
|
my ($self, $form, $field) = @_; |
9
|
|
|
|
|
|
|
|
10
|
34
|
|
|
|
|
93
|
my $type = $field->widget; |
11
|
34
|
50
|
|
|
|
215
|
my $code = $self->can("widget_${type}") or die "unknown widget type: $type"; |
12
|
34
|
|
|
|
|
105
|
$code->( |
13
|
|
|
|
|
|
|
$self, $form, $field |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _attr { |
18
|
57
|
|
|
57
|
|
102
|
my $attr = shift; |
19
|
|
|
|
|
|
|
|
20
|
57
|
|
|
|
|
91
|
my @ret; |
21
|
|
|
|
|
|
|
|
22
|
57
|
|
|
|
|
204
|
for my $key (sort keys %$attr) { |
23
|
132
|
|
|
|
|
631
|
push @ret, sprintf(q{%s="%s"}, HTML::Escape::escape_html($key), HTML::Escape::escape_html($attr->{$key})); |
24
|
|
|
|
|
|
|
} |
25
|
57
|
|
|
|
|
444
|
join ' ', @ret; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub widget_input { |
30
|
19
|
|
|
19
|
0
|
45
|
my ($self, $form, $field) = @_; |
31
|
|
|
|
|
|
|
|
32
|
19
|
|
|
|
|
66
|
my $value = $form->fillin_param($field->{name}); |
33
|
19
|
100
|
|
|
|
63
|
if (defined $value) { |
34
|
6
|
|
|
|
|
50
|
$field->value($value); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
19
|
|
|
|
|
69
|
return '<input ' . _attr($field->attr) . " />"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub widget_textarea { |
41
|
2
|
|
|
2
|
0
|
6
|
my ($self, $form, $field) = @_; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
100
|
|
|
8
|
my $value = $form->fillin_param($field->{name}) || ''; |
44
|
2
|
|
|
|
|
4
|
my $attr = {%{$field->attr}}; # shallow copy |
|
2
|
|
|
|
|
9
|
|
45
|
2
|
|
|
|
|
6
|
delete $attr->{type}; # textarea tag doesn't need this |
46
|
2
|
|
|
|
|
6
|
return '<textarea ' . _attr($attr) . ">" . HTML::Escape::escape_html($value) . "</textarea>"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub widget_select { |
50
|
12
|
|
|
12
|
0
|
33
|
my ($self, $form, $field) = @_; |
51
|
|
|
|
|
|
|
|
52
|
12
|
|
|
|
|
33
|
my $choices = $field->{choices}; |
53
|
|
|
|
|
|
|
|
54
|
12
|
|
|
|
|
38
|
my $value = $form->fillin_param($field->{name}); |
55
|
|
|
|
|
|
|
|
56
|
12
|
|
|
|
|
23
|
my @t; |
57
|
12
|
|
|
|
|
50
|
push @t, sprintf(q{<select %s>}, _attr($field->attr)); |
58
|
12
|
|
|
|
|
46
|
for (my $i=0; $i<@$choices; $i+=2) { |
59
|
109
|
|
|
|
|
219
|
my ($a, $b) = ($choices->[$i], $choices->[$i+1]); |
60
|
109
|
100
|
100
|
|
|
678
|
push @t, sprintf( |
61
|
|
|
|
|
|
|
q{<option value="%s"%s>%s</option>}, |
62
|
|
|
|
|
|
|
HTML::Escape::escape_html($a), |
63
|
|
|
|
|
|
|
(defined $value && $value eq $a ? ' selected="selected"' : ''), |
64
|
|
|
|
|
|
|
HTML::Escape::escape_html($b)); |
65
|
|
|
|
|
|
|
} |
66
|
12
|
|
|
|
|
25
|
push @t, q{</select>}; |
67
|
12
|
|
|
|
|
76
|
return join "\n", @t; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub widget_radio { |
71
|
6
|
|
|
6
|
0
|
15
|
my ($self, $form, $field) = @_; |
72
|
|
|
|
|
|
|
|
73
|
6
|
|
|
|
|
15
|
my $choices = $field->{choices}; |
74
|
|
|
|
|
|
|
|
75
|
6
|
|
|
|
|
19
|
my $value = $form->fillin_param($field->{name}); |
76
|
|
|
|
|
|
|
|
77
|
6
|
100
|
66
|
|
|
38
|
my $label_css = ($field->has_item_label_class() && $field->item_label_class ne '') |
78
|
|
|
|
|
|
|
? sprintf(q{ class="%s"}, $field->item_label_class) |
79
|
|
|
|
|
|
|
: ''; |
80
|
|
|
|
|
|
|
|
81
|
6
|
|
|
|
|
12
|
my @t; |
82
|
6
|
|
|
|
|
13
|
push @t, "<ul>"; |
83
|
6
|
|
|
|
|
25
|
for (my $i=0; $i<@$choices; $i+=2) { |
84
|
18
|
|
|
|
|
48
|
my ($a, $b) = ($choices->[$i], $choices->[$i+1]); |
85
|
|
|
|
|
|
|
push @t, sprintf( |
86
|
|
|
|
|
|
|
q{<li><label%s><input %s type="radio" value="%s"%s />%s</label></li>}, |
87
|
|
|
|
|
|
|
$label_css, |
88
|
|
|
|
|
|
|
_attr({ |
89
|
18
|
|
|
|
|
139
|
%{ $field->attr }, |
90
|
18
|
100
|
100
|
|
|
31
|
id => sprintf( $field->id_tmpl, $field->{name}, $i / 2 ), |
91
|
|
|
|
|
|
|
}), |
92
|
|
|
|
|
|
|
HTML::Escape::escape_html($a), |
93
|
|
|
|
|
|
|
(defined $value && $value eq $a ? ' checked="checked"' : ''), |
94
|
|
|
|
|
|
|
HTML::Escape::escape_html($b) |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
6
|
|
|
|
|
14
|
push @t, "</ul>"; |
98
|
6
|
|
|
|
|
31
|
join "\n", @t; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub widget_checkbox { |
102
|
2
|
|
|
2
|
0
|
6
|
my ($self, $form, $field) = @_; |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
4
|
my $choices = $field->{choices}; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
7
|
my $values = $form->fillin_param($field->{name}); |
107
|
2
|
50
|
|
|
|
7
|
unless (ref $values) { |
108
|
2
|
50
|
|
|
|
6
|
$values = defined $values ? [$values] : []; |
109
|
|
|
|
|
|
|
} |
110
|
2
|
100
|
66
|
|
|
18
|
my $label_css = ($field->has_item_label_class() && $field->item_label_class ne '') |
111
|
|
|
|
|
|
|
? sprintf(q{ class="%s"}, $field->item_label_class) |
112
|
|
|
|
|
|
|
: ''; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
5
|
my @t; |
115
|
2
|
|
|
|
|
3
|
push @t, "<ul>"; |
116
|
2
|
|
|
|
|
8
|
for (my $i=0; $i<@$choices; $i+=2) { |
117
|
6
|
|
|
|
|
17
|
my ($val, $label) = ($choices->[$i], $choices->[$i+1]); |
118
|
6
|
|
|
|
|
11
|
my $checked = grep /^$val$/, @$values; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
push @t, sprintf( |
121
|
|
|
|
|
|
|
'<li><label%s><input %s type="checkbox" value="%s"%s />%s</label></li>', |
122
|
|
|
|
|
|
|
$label_css, |
123
|
|
|
|
|
|
|
_attr({ |
124
|
6
|
|
|
|
|
43
|
%{ $field->attr }, |
125
|
6
|
50
|
|
|
|
10
|
id => sprintf( $field->id_tmpl, $field->{name}, $i / 2 ), |
126
|
|
|
|
|
|
|
}), |
127
|
|
|
|
|
|
|
HTML::Escape::escape_html($val), |
128
|
|
|
|
|
|
|
($checked ? ' checked="checked"' : ''), |
129
|
|
|
|
|
|
|
HTML::Escape::escape_html($label), |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
2
|
|
|
|
|
4
|
push @t, "</ul>"; |
133
|
2
|
|
|
|
|
12
|
join "\n", @t; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub widget_date { |
137
|
2
|
|
|
2
|
0
|
6
|
my ($self, $form, $field) = @_; |
138
|
2
|
50
|
|
|
|
9
|
my $name = $field->{name} or die "missing name"; |
139
|
2
|
50
|
|
|
|
7
|
my $years = $field->{years} or die "missing years"; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $set = sub { |
142
|
6
|
|
|
6
|
|
13
|
my ($choices, $suffix) = @_; |
143
|
6
|
|
|
|
|
30
|
$self->widget_select( |
144
|
|
|
|
|
|
|
$form, |
145
|
|
|
|
|
|
|
HTML::Shakan::Field::Choice->new( |
146
|
|
|
|
|
|
|
name => "${name}_${suffix}", |
147
|
|
|
|
|
|
|
choices => [zip(@$choices, @$choices)], |
148
|
|
|
|
|
|
|
) |
149
|
|
|
|
|
|
|
); |
150
|
2
|
|
|
|
|
10
|
}; |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
6
|
my @t; |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
5
|
push @t, '<span>'; |
155
|
|
|
|
|
|
|
|
156
|
2
|
|
|
|
|
6
|
push @t, $set->($years, 'year'); |
157
|
2
|
|
|
|
|
20
|
push @t, $set->([1..12], 'month'); |
158
|
2
|
|
|
|
|
19
|
push @t, $set->([1..31], 'day'); |
159
|
|
|
|
|
|
|
|
160
|
2
|
|
|
|
|
15
|
push @t, '</span>'; |
161
|
|
|
|
|
|
|
|
162
|
2
|
|
|
|
|
22
|
join "\n", @t; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub field_filter { |
166
|
68
|
|
|
68
|
0
|
185
|
my ($self, $form, $field, $params) = @_; |
167
|
|
|
|
|
|
|
|
168
|
68
|
100
|
|
|
|
360
|
if ($field->widget eq 'date') { |
169
|
4
|
|
|
|
|
8
|
my @c; |
170
|
4
|
|
|
|
|
11
|
for my $k (qw/year month day/) { |
171
|
12
|
|
|
|
|
45
|
my $key = $field->name . '_' . $k; |
172
|
12
|
|
|
|
|
43
|
my $v = $form->request->param($key); |
173
|
12
|
100
|
|
|
|
281
|
if (defined $v) { |
174
|
9
|
|
|
|
|
21
|
push @c, $v; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
4
|
100
|
|
|
|
15
|
if (@c == 3) { |
179
|
3
|
|
|
|
|
20
|
$params->{$field->name} = join '-', @c; # http-date style |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
__END__ |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 NAME |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
HTML::Shakan::Widgets::Simple - simple default HTML widgets |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 DESCRIPTION |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This is basic default widgets class. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This module generates basic XHTML. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHORS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Tokuhiro Matsuno |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SEE ALSO |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L<HTML::Shakan> |
204
|
|
|
|
|
|
|
|