line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
52
|
|
|
52
|
|
1241
|
use strict; |
|
52
|
|
|
|
|
115
|
|
|
52
|
|
|
|
|
3275
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Element::Select; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Element::Select::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Select form field |
6
|
|
|
|
|
|
|
|
7
|
52
|
|
|
52
|
|
1565
|
use Moose; |
|
52
|
|
|
|
|
117
|
|
|
52
|
|
|
|
|
406
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Element::Group'; |
11
|
|
|
|
|
|
|
|
12
|
52
|
|
|
52
|
|
368825
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
52
|
|
|
|
|
517
|
|
|
52
|
|
|
|
|
6684
|
|
13
|
52
|
|
|
52
|
|
577
|
use HTML::FormFu::Util qw( append_xml_attribute process_attrs ); |
|
52
|
|
|
|
|
1240
|
|
|
52
|
|
|
|
|
3556
|
|
14
|
52
|
|
|
52
|
|
399
|
use List::Util 1.33 qw( any ); |
|
52
|
|
|
|
|
1504
|
|
|
52
|
|
|
|
|
33893
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_attr_accessors(qw( multiple size )); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
after BUILD => sub { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$self->layout_field_filename('field_layout_select_field'); |
22
|
|
|
|
|
|
|
$self->multi_value(1); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _prepare_attrs { |
28
|
8018
|
|
|
8018
|
|
13800
|
my ( $self, $submitted, $value, $default, $option ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
8018
|
100
|
100
|
|
|
133160
|
if ( $submitted |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
31
|
|
|
|
|
|
|
&& defined $value |
32
|
|
|
|
|
|
|
&& (ref $value eq 'ARRAY' |
33
|
5
|
|
|
5
|
|
54
|
? any { $_ eq $option->{value} } @$value |
34
|
|
|
|
|
|
|
: $value eq $option->{value} ) ) |
35
|
|
|
|
|
|
|
{ |
36
|
151
|
|
|
|
|
422
|
$option->{attributes}{selected} = 'selected'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($submitted |
39
|
|
|
|
|
|
|
&& $self->retain_default |
40
|
|
|
|
|
|
|
&& ( !defined $value || $value eq $EMPTY_STR ) |
41
|
|
|
|
|
|
|
&& defined( $self->value ) |
42
|
|
|
|
|
|
|
&& $self->value eq $option->{value} ) |
43
|
|
|
|
|
|
|
{ |
44
|
4
|
|
|
|
|
19
|
$option->{attributes}{selected} = 'selected'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($submitted) { |
47
|
3384
|
|
|
|
|
5562
|
delete $option->{attributes}{selected}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( |
50
|
|
|
|
|
|
|
defined $default |
51
|
|
|
|
|
|
|
&& (ref $default eq 'ARRAY' |
52
|
46
|
|
|
46
|
|
125
|
? any { $_ eq $option->{value} } @$default |
53
|
|
|
|
|
|
|
: $default eq $option->{value} ) ) |
54
|
|
|
|
|
|
|
{ |
55
|
191
|
|
|
|
|
570
|
$option->{attributes}{selected} = 'selected'; |
56
|
|
|
|
|
|
|
} |
57
|
8018
|
|
|
|
|
15980
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _string_field { |
61
|
235
|
|
|
235
|
|
540
|
my ( $self, $render ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# select_tag template |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $html .= sprintf qq{<select name="%s"%s>\n}, |
66
|
|
|
|
|
|
|
$render->{nested_name}, |
67
|
235
|
|
|
|
|
947
|
process_attrs( $render->{attributes} ); |
68
|
|
|
|
|
|
|
|
69
|
235
|
|
|
|
|
534
|
for my $option ( @{ $render->{options} } ) { |
|
235
|
|
|
|
|
714
|
|
70
|
3957
|
100
|
|
|
|
7490
|
if ( exists $option->{group} ) { |
71
|
14
|
|
|
|
|
23
|
$html .= "<optgroup"; |
72
|
|
|
|
|
|
|
|
73
|
14
|
100
|
|
|
|
32
|
if ( defined $option->{label} ) { |
74
|
8
|
|
|
|
|
15
|
$html .= sprintf qq{ label="%s"}, $option->{label}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
14
|
|
|
|
|
34
|
$html .= sprintf "%s>\n", process_attrs( $option->{attributes} ); |
78
|
|
|
|
|
|
|
|
79
|
14
|
|
|
|
|
26
|
for my $item ( @{ $option->{group} } ) { |
|
14
|
|
|
|
|
27
|
|
80
|
|
|
|
|
|
|
$html .= sprintf qq{<option value="%s"%s>%s</option>\n}, |
81
|
|
|
|
|
|
|
$item->{value}, |
82
|
|
|
|
|
|
|
process_attrs( $item->{attributes} ), |
83
|
|
|
|
|
|
|
$item->{label}, |
84
|
28
|
|
|
|
|
58
|
; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
14
|
|
|
|
|
31
|
$html .= "</optgroup>\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
|
|
|
|
|
|
$html .= sprintf qq{<option value="%s"%s>%s</option>\n}, |
91
|
|
|
|
|
|
|
$option->{value}, |
92
|
|
|
|
|
|
|
process_attrs( $option->{attributes} ), |
93
|
|
|
|
|
|
|
$option->{label}, |
94
|
3943
|
|
|
|
|
7543
|
; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
235
|
|
|
|
|
526
|
$html .= "</select>"; |
99
|
|
|
|
|
|
|
|
100
|
235
|
|
|
|
|
1186
|
return $html; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
HTML::FormFu::Element::Select - Select form field |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 2.07 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
YAML config: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
--- |
126
|
|
|
|
|
|
|
elements: |
127
|
|
|
|
|
|
|
- type: Select |
128
|
|
|
|
|
|
|
name: sex |
129
|
|
|
|
|
|
|
options: |
130
|
|
|
|
|
|
|
- [ 'm', 'Male' ] |
131
|
|
|
|
|
|
|
- [ 'f', 'Female' ] |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 DESCRIPTION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Select form field. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Supports optgroups, see L<HTML::FormFu::Role::Element::Group/options> for |
138
|
|
|
|
|
|
|
details. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 METHODS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 options |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/options>. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 values |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/values>. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 value_range |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/value_range>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 empty_first |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/empty_first>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 empty_first_label |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See L<HTML::FormFu::Role::Element::Group/empty_first_label>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
165
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Group>, |
166
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Field>, |
167
|
|
|
|
|
|
|
L<HTML::FormFu::Element> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
L<HTML::FormFu> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
178
|
|
|
|
|
|
|
the same terms as Perl itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHOR |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
189
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |