line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormBuilder::Select; |
2
|
4
|
|
|
4
|
|
2422
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
102
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
160
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
241
|
|
8
|
4
|
|
|
4
|
|
861
|
use Moo; |
|
4
|
|
|
|
|
15236
|
|
|
4
|
|
|
|
|
22
|
|
9
|
4
|
|
|
4
|
|
3350
|
use namespace::clean; |
|
4
|
|
|
|
|
13176
|
|
|
4
|
|
|
|
|
28
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
HTML::FormBuilder::Select - Select Element Handling for BOM Forms |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 Synopsis |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $select = HTML::FormBuilder::Select->new( |
20
|
|
|
|
|
|
|
id => 'my-select', |
21
|
|
|
|
|
|
|
name => 'my_select', |
22
|
|
|
|
|
|
|
options => [{value => 'foo', text => 'Foo'}, {value => 'bar', text => 'Bar'}], |
23
|
|
|
|
|
|
|
values => qw(foo), |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
$select->values('bar'); # set only 'bar' |
26
|
|
|
|
|
|
|
$select->values('foo', 'bar'); # set only 'foo' |
27
|
|
|
|
|
|
|
my $html = $select->widget_html; |
28
|
|
|
|
|
|
|
my $hidden_input_html = $select->hidden_html; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 PROPERTIES |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 id - id property of form element |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has id => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => \&is_str, |
39
|
|
|
|
|
|
|
lazy => 1, |
40
|
|
|
|
|
|
|
builder => '_build_id' |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _build_id { |
44
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
45
|
0
|
|
|
|
|
0
|
return $self->name; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 name - name property of form element |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has name => ( |
53
|
|
|
|
|
|
|
is => 'ro', |
54
|
|
|
|
|
|
|
isa => \&is_str, |
55
|
|
|
|
|
|
|
required => '1' |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 options - option arrayref to generate options |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has options => ( |
63
|
|
|
|
|
|
|
is => 'rw', |
64
|
|
|
|
|
|
|
isa => sub { |
65
|
|
|
|
|
|
|
die "$_[0] is not ArrayRef[HashRef[Any]]" |
66
|
|
|
|
|
|
|
unless (ref($_[0]) eq 'ARRAY' && ref($_[0][0]) eq 'HASH'); |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 values - values (by value) selected |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has values => ( |
75
|
|
|
|
|
|
|
is => 'rw', |
76
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not a Arrayref" unless (ref($_[0]) eq 'ARRAY') }, |
77
|
|
|
|
|
|
|
default => sub { [] }, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 value |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Actually just a method that grabs the first value from values |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub value { |
87
|
29
|
|
|
29
|
1
|
66
|
my $self = shift; |
88
|
29
|
|
|
|
|
39
|
my $val = shift; |
89
|
29
|
|
|
|
|
622
|
my $values = $self->values; |
90
|
29
|
100
|
66
|
|
|
999
|
return $values->[0] if defined $values and not defined $val; |
91
|
13
|
50
|
|
|
|
287
|
return $self->values([$val]) if defined $val; |
92
|
0
|
|
|
|
|
0
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 widget_html |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub widget_html { |
102
|
18
|
|
|
18
|
1
|
5681
|
my $self = shift; |
103
|
18
|
|
|
|
|
355
|
my $html = '<select id="' . $self->id . '" name="' . $self->name . '">'; |
104
|
18
|
|
|
|
|
1926
|
$html .= $self->_option_html($_) for @{$self->options}; |
|
18
|
|
|
|
|
327
|
|
105
|
18
|
|
|
|
|
33
|
$html .= "</select>"; |
106
|
18
|
|
|
|
|
51
|
return $html; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _option_html { |
110
|
36
|
|
|
36
|
|
1691
|
my ($self, $optionhash) = @_; |
111
|
36
|
|
|
|
|
62
|
my $value = $optionhash->{value}; |
112
|
36
|
|
100
|
|
|
140
|
my $text = $optionhash->{text} // $value; |
113
|
36
|
|
|
|
|
48
|
my $selected = ''; |
114
|
36
|
|
100
|
|
|
159
|
$optionhash->{disabled} //= ''; |
115
|
36
|
100
|
|
|
|
43
|
$selected = ' SELECTED' if grep { $_ eq $value } @{$self->values}; |
|
22
|
|
|
|
|
1193
|
|
|
36
|
|
|
|
|
687
|
|
116
|
36
|
|
|
|
|
260
|
return qq|<option value="$value"$selected $optionhash->{disabled}>$text</option>|; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 hidden_html |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub hidden_html { |
124
|
3
|
|
|
3
|
1
|
1403
|
my $self = shift; |
125
|
3
|
|
50
|
|
|
65
|
return '<input type="hidden" id="' . $self->id . '" name="' . $self->name . '" value="' . ($self->value // '') . '" />'; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub is_str { |
129
|
40
|
50
|
33
|
40
|
0
|
9935
|
die "$_[0] is not a string" unless defined($_[0]) && !ref($_[0]); |
130
|
40
|
|
|
|
|
771
|
return 1; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|