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