line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormBuilder::Select; |
2
|
4
|
|
|
4
|
|
1472
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
88
|
|
3
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
71
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
12
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
168
|
|
6
|
4
|
|
|
4
|
|
452
|
use Moo; |
|
4
|
|
|
|
|
9360
|
|
|
4
|
|
|
|
|
19
|
|
7
|
4
|
|
|
4
|
|
2029
|
use namespace::clean; |
|
4
|
|
|
|
|
8720
|
|
|
4
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.12'; ## VERSION |
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
|
39
|
my $self = shift; |
88
|
29
|
|
|
|
|
25
|
my $val = shift; |
89
|
29
|
|
|
|
|
480
|
my $values = $self->values; |
90
|
29
|
100
|
66
|
|
|
614
|
return $values->[0] if defined $values and not defined $val; |
91
|
13
|
50
|
|
|
|
186
|
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
|
5269
|
my $self = shift; |
103
|
18
|
|
|
|
|
292
|
my $html = '<select id="' . $self->id . '" name="' . $self->name . '">'; |
104
|
18
|
|
|
|
|
1575
|
$html .= $self->_option_html($_) for @{$self->options}; |
|
18
|
|
|
|
|
194
|
|
105
|
18
|
|
|
|
|
24
|
$html .= "</select>"; |
106
|
18
|
|
|
|
|
49
|
return $html; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _option_html { |
110
|
36
|
|
|
36
|
|
1268
|
my ($self, $optionhash) = @_; |
111
|
36
|
|
|
|
|
34
|
my $value = $optionhash->{value}; |
112
|
36
|
|
100
|
|
|
93
|
my $text = $optionhash->{text} // $value; |
113
|
36
|
|
|
|
|
30
|
my $selected = ''; |
114
|
36
|
|
100
|
|
|
90
|
$optionhash->{disabled} //= ''; |
115
|
36
|
100
|
|
|
|
41
|
$selected = ' SELECTED' if grep { $_ eq $value } @{$self->values}; |
|
22
|
|
|
|
|
931
|
|
|
36
|
|
|
|
|
450
|
|
116
|
36
|
|
|
|
|
171
|
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
|
1437
|
my $self = shift; |
125
|
3
|
|
50
|
|
|
46
|
return '<input type="hidden" id="' . $self->id . '" name="' . $self->name . '" value="' . ($self->value // '') . '" />'; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 is_str |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub is_str { |
133
|
40
|
50
|
33
|
40
|
1
|
6352
|
die "$_[0] is not a string" unless defined($_[0]) && !ref($_[0]); |
134
|
40
|
|
|
|
|
523
|
return 1; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|