line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Element::Select; |
2
|
|
|
|
|
|
|
|
3
|
51
|
|
|
51
|
|
1006
|
use strict; |
|
51
|
|
|
|
|
368
|
|
|
51
|
|
|
|
|
2287
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
51
|
|
|
51
|
|
190
|
use Moose; |
|
51
|
|
|
|
|
58
|
|
|
51
|
|
|
|
|
318
|
|
7
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Element::Group'; |
10
|
|
|
|
|
|
|
|
11
|
51
|
|
|
51
|
|
234452
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
51
|
|
|
|
|
79
|
|
|
51
|
|
|
|
|
5364
|
|
12
|
51
|
|
|
51
|
|
226
|
use HTML::FormFu::Util qw( append_xml_attribute process_attrs ); |
|
51
|
|
|
|
|
54
|
|
|
51
|
|
|
|
|
2694
|
|
13
|
51
|
|
|
51
|
|
241
|
use List::Util 1.33 qw( any ); |
|
51
|
|
|
|
|
1373
|
|
|
51
|
|
|
|
|
24854
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_attr_accessors(qw( multiple size )); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
after BUILD => sub { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->layout_field_filename('field_layout_select_field'); |
21
|
|
|
|
|
|
|
$self->multi_value(1); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _prepare_attrs { |
27
|
8014
|
|
|
8014
|
|
6742
|
my ( $self, $submitted, $value, $default, $option ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
8014
|
100
|
100
|
|
|
116254
|
if ( $submitted |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
30
|
|
|
|
|
|
|
&& defined $value |
31
|
|
|
|
|
|
|
&& (ref $value eq 'ARRAY' |
32
|
5
|
|
|
5
|
|
41
|
? any { $_ eq $option->{value} } @$value |
33
|
|
|
|
|
|
|
: $value eq $option->{value} ) ) |
34
|
|
|
|
|
|
|
{ |
35
|
151
|
|
|
|
|
274
|
$option->{attributes}{selected} = 'selected'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ($submitted |
38
|
|
|
|
|
|
|
&& $self->retain_default |
39
|
|
|
|
|
|
|
&& ( !defined $value || $value eq $EMPTY_STR ) |
40
|
|
|
|
|
|
|
&& defined( $self->value ) |
41
|
|
|
|
|
|
|
&& $self->value eq $option->{value} ) |
42
|
|
|
|
|
|
|
{ |
43
|
4
|
|
|
|
|
11
|
$option->{attributes}{selected} = 'selected'; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ($submitted) { |
46
|
3380
|
|
|
|
|
2720
|
delete $option->{attributes}{selected}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( |
49
|
|
|
|
|
|
|
defined $default |
50
|
|
|
|
|
|
|
&& (ref $default eq 'ARRAY' |
51
|
46
|
|
|
46
|
|
80
|
? any { $_ eq $option->{value} } @$default |
52
|
|
|
|
|
|
|
: $default eq $option->{value} ) ) |
53
|
|
|
|
|
|
|
{ |
54
|
191
|
|
|
|
|
363
|
$option->{attributes}{selected} = 'selected'; |
55
|
|
|
|
|
|
|
} |
56
|
8014
|
|
|
|
|
10853
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _string_field { |
60
|
233
|
|
|
233
|
|
272
|
my ( $self, $render ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# select_tag template |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $html .= sprintf qq{<select name="%s"%s>\n}, |
65
|
|
|
|
|
|
|
$render->{nested_name}, |
66
|
233
|
|
|
|
|
724
|
process_attrs( $render->{attributes} ); |
67
|
|
|
|
|
|
|
|
68
|
233
|
|
|
|
|
587
|
for my $option ( @{ $render->{options} } ) { |
|
233
|
|
|
|
|
493
|
|
69
|
3953
|
100
|
|
|
|
4335
|
if ( exists $option->{group} ) { |
70
|
14
|
|
|
|
|
14
|
$html .= "<optgroup"; |
71
|
|
|
|
|
|
|
|
72
|
14
|
100
|
|
|
|
25
|
if ( defined $option->{label} ) { |
73
|
8
|
|
|
|
|
14
|
$html .= sprintf qq{ label="%s"}, $option->{label}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
14
|
|
|
|
|
22
|
$html .= sprintf "%s>\n", process_attrs( $option->{attributes} ); |
77
|
|
|
|
|
|
|
|
78
|
14
|
|
|
|
|
19
|
for my $item ( @{ $option->{group} } ) { |
|
14
|
|
|
|
|
19
|
|
79
|
|
|
|
|
|
|
$html .= sprintf qq{<option value="%s"%s>%s</option>\n}, |
80
|
|
|
|
|
|
|
$item->{value}, |
81
|
|
|
|
|
|
|
process_attrs( $item->{attributes} ), |
82
|
|
|
|
|
|
|
$item->{label}, |
83
|
28
|
|
|
|
|
39
|
; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
14
|
|
|
|
|
19
|
$html .= "</optgroup>\n"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
|
|
|
|
|
|
$html .= sprintf qq{<option value="%s"%s>%s</option>\n}, |
90
|
|
|
|
|
|
|
$option->{value}, |
91
|
|
|
|
|
|
|
process_attrs( $option->{attributes} ), |
92
|
|
|
|
|
|
|
$option->{label}, |
93
|
3939
|
|
|
|
|
5491
|
; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
233
|
|
|
|
|
366
|
$html .= "</select>"; |
98
|
|
|
|
|
|
|
|
99
|
233
|
|
|
|
|
1059
|
return $html; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
HTML::FormFu::Element::Select - Select form field |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 2.05 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SYNOPSIS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
YAML config: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
--- |
121
|
|
|
|
|
|
|
elements: |
122
|
|
|
|
|
|
|
- type: Select |
123
|
|
|
|
|
|
|
name: sex |
124
|
|
|
|
|
|
|
options: |
125
|
|
|
|
|
|
|
- [ 'm', 'Male' ] |
126
|
|
|
|
|
|
|
- [ 'f', 'Female' ] |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 DESCRIPTION |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Select form field. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Supports optgroups, see L<HTML::FormFu::Role::Element::Group/options> for |
133
|
|
|
|
|
|
|
details. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 METHODS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 options |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/options>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 values |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/values>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 value_range |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/value_range>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 empty_first |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/empty_first>. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 empty_first_label |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/empty_first_label>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SEE ALSO |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
160
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Group>, |
161
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Field>, |
162
|
|
|
|
|
|
|
L<HTML::FormFu::Element> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<HTML::FormFu> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 LICENSE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
173
|
|
|
|
|
|
|
the same terms as Perl itself. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |