line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormBuilder::FieldSet; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
24
|
use strict; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
164
|
|
4
|
7
|
|
|
7
|
|
23
|
use warnings; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
132
|
|
5
|
7
|
|
|
7
|
|
93
|
use 5.008_005; |
|
7
|
|
|
|
|
18
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
2595
|
use HTML::FormBuilder::Field; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
188
|
|
8
|
7
|
|
|
7
|
|
37
|
use Carp; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
362
|
|
9
|
7
|
|
|
7
|
|
26
|
use Scalar::Util qw(weaken blessed); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
233
|
|
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
40
|
use Moo; |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
34
|
|
12
|
7
|
|
|
7
|
|
1400
|
use namespace::clean; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
43
|
|
13
|
|
|
|
|
|
|
extends qw(HTML::FormBuilder::Base); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.12'; ## VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has data => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { |
20
|
|
|
|
|
|
|
my $data = shift; |
21
|
|
|
|
|
|
|
croak('data should be a hashref') unless ref($data) eq 'HASH'; |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
default => sub { |
24
|
|
|
|
|
|
|
{}; |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has fields => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => sub { |
31
|
|
|
|
|
|
|
my $fields = shift; |
32
|
|
|
|
|
|
|
croak('fields should be an arrayref') unless ref($fields) eq 'ARRAY'; |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
default => sub { |
35
|
|
|
|
|
|
|
[]; |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add_field { |
40
|
97
|
|
|
97
|
1
|
1267
|
my $self = shift; |
41
|
97
|
|
|
|
|
64
|
my $_args = shift; |
42
|
|
|
|
|
|
|
|
43
|
97
|
|
|
|
|
1278
|
my $field = HTML::FormBuilder::Field->new( |
44
|
|
|
|
|
|
|
data => $_args, |
45
|
|
|
|
|
|
|
classes => $self->classes, |
46
|
|
|
|
|
|
|
localize => $self->localize |
47
|
|
|
|
|
|
|
); |
48
|
97
|
|
|
|
|
466
|
push @{$self->{'fields'}}, $field; |
|
97
|
|
|
|
|
141
|
|
49
|
|
|
|
|
|
|
|
50
|
97
|
|
|
|
|
120
|
return $field; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub add_fields { |
54
|
1
|
|
|
1
|
1
|
1128
|
my ($self, @field_args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
2
|
for my $field_arg (@field_args) { |
57
|
2
|
|
|
|
|
4
|
$self->add_field($field_arg); |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
|
|
4
|
return scalar @field_args; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
##################################################################### |
63
|
|
|
|
|
|
|
# Usage : generate the form content for a fieldset |
64
|
|
|
|
|
|
|
# Purpose : check and parse the parameters and generate the form |
65
|
|
|
|
|
|
|
# properly |
66
|
|
|
|
|
|
|
# Returns : a piece of form HTML for a fieldset |
67
|
|
|
|
|
|
|
# Parameters : fieldset |
68
|
|
|
|
|
|
|
# Comments : |
69
|
|
|
|
|
|
|
# See Also : |
70
|
|
|
|
|
|
|
##################################################################### |
71
|
|
|
|
|
|
|
sub build { |
72
|
18
|
|
|
18
|
1
|
19
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
18
|
|
|
|
|
20
|
my $data = $self->{data}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#FIXME this attribute should be deleted, or it will emit to the html code |
77
|
18
|
|
|
|
|
15
|
my $fieldset_group = $data->{'group'}; |
78
|
18
|
100
|
|
|
|
28
|
my $stacked = defined $data->{'stacked'} ? $data->{'stacked'} : 1; |
79
|
|
|
|
|
|
|
|
80
|
18
|
100
|
|
|
|
39
|
if (not $fieldset_group) { |
81
|
17
|
|
|
|
|
18
|
$fieldset_group = 'no-group'; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
18
|
|
|
|
|
30
|
my $fieldset_html = $self->_build_fieldset_foreword(); |
85
|
|
|
|
|
|
|
|
86
|
18
|
|
|
|
|
16
|
my $input_fields_html = ''; |
87
|
|
|
|
|
|
|
|
88
|
18
|
|
|
|
|
13
|
foreach my $input_field (@{$self->{'fields'}}) { |
|
18
|
|
|
|
|
52
|
|
89
|
71
|
|
|
|
|
184
|
$input_fields_html .= $input_field->build({stacked => $stacked}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
18
|
100
|
|
|
|
37
|
if ($stacked == 0) { |
93
|
1
|
|
|
|
|
5
|
$input_fields_html = $self->_build_element_and_attributes('div', {class => $self->{classes}{'no_stack_field_parent'}}, $input_fields_html); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
18
|
|
|
|
|
40
|
$fieldset_html .= $input_fields_html; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# message at the bottom of the fieldset |
99
|
18
|
100
|
|
|
|
34
|
if (defined $data->{'footer'}) { |
100
|
1
|
|
|
|
|
2
|
my $footer = delete $data->{'footer'}; |
101
|
1
|
|
|
|
|
4
|
$fieldset_html .= qq{<div class="$self->{classes}{fieldset_footer}">$footer</div>}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
18
|
|
|
|
|
47
|
$fieldset_html = $self->_build_element_and_attributes('fieldset', $data, $fieldset_html); |
105
|
|
|
|
|
|
|
|
106
|
18
|
50
|
33
|
|
|
103
|
if ( |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
107
|
|
|
|
|
|
|
(not $data->{'id'} or $data->{'id'} ne 'formlayout') |
108
|
|
|
|
|
|
|
and (not $data->{'class'} |
109
|
|
|
|
|
|
|
or $data->{'class'} !~ /no-wrap|invisible/)) |
110
|
|
|
|
|
|
|
{ |
111
|
18
|
|
|
|
|
32
|
$fieldset_html = $self->_wrap_fieldset($fieldset_html); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
18
|
|
|
|
|
44
|
return ($fieldset_group, $fieldset_html); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
##################################################################### |
118
|
|
|
|
|
|
|
# Usage : generate the form content for a fieldset foreword thing |
119
|
|
|
|
|
|
|
# Purpose : check and parse the parameters and generate the form |
120
|
|
|
|
|
|
|
# properly |
121
|
|
|
|
|
|
|
# Returns : a piece of form HTML code for a fieldset foreword |
122
|
|
|
|
|
|
|
# Parameters : input_field, stacked |
123
|
|
|
|
|
|
|
# Comments : |
124
|
|
|
|
|
|
|
# See Also : |
125
|
|
|
|
|
|
|
##################################################################### |
126
|
|
|
|
|
|
|
sub _build_fieldset_foreword { |
127
|
18
|
|
|
18
|
|
16
|
my $self = shift; |
128
|
18
|
|
|
|
|
19
|
my $data = $self->{data}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# fieldset legend |
131
|
18
|
|
|
|
|
17
|
my $legend = ''; |
132
|
18
|
100
|
|
|
|
30
|
if (defined $data->{'legend'}) { |
133
|
1
|
|
|
|
|
3
|
$legend = qq{<legend>$data->{legend}</legend>}; |
134
|
1
|
|
|
|
|
1
|
undef $data->{'legend'}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# header at the top of the fieldset |
138
|
18
|
|
|
|
|
14
|
my $header = ''; |
139
|
18
|
100
|
|
|
|
30
|
if (defined $data->{'header'}) { |
140
|
1
|
|
|
|
|
2
|
$header = qq{<h2>$data->{header}</h2>}; |
141
|
1
|
|
|
|
|
2
|
undef $data->{'header'}; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# message at the top of the fieldset |
145
|
18
|
|
|
|
|
18
|
my $comment = ''; |
146
|
18
|
100
|
|
|
|
35
|
if (defined $data->{'comment'}) { |
147
|
1
|
|
|
|
|
4
|
$comment = qq{<div class="$self->{classes}{comment}"><p>$data->{comment}</p></div>}; |
148
|
1
|
|
|
|
|
1
|
undef $data->{'comment'}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
18
|
|
|
|
|
37
|
return $legend . $header . $comment; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
##################################################################### |
155
|
|
|
|
|
|
|
# Usage : $self->_wrap_fieldset($fieldset_html) |
156
|
|
|
|
|
|
|
# Purpose : wrap fieldset html by template |
157
|
|
|
|
|
|
|
# Returns : HTML |
158
|
|
|
|
|
|
|
# Comments : |
159
|
|
|
|
|
|
|
# See Also : |
160
|
|
|
|
|
|
|
##################################################################### |
161
|
|
|
|
|
|
|
sub _wrap_fieldset { |
162
|
18
|
|
|
18
|
|
33
|
my ($self, $fieldset_html) = @_; |
163
|
|
|
|
|
|
|
|
164
|
18
|
|
|
|
|
61
|
my $fieldset_template = <<EOF; |
165
|
|
|
|
|
|
|
<div class="rbox form"> |
166
|
|
|
|
|
|
|
<div class="rbox-wrap"> |
167
|
|
|
|
|
|
|
$fieldset_html |
168
|
|
|
|
|
|
|
<span class="tl"> </span><span class="tr"> </span><span class="bl"> </span><span class="br"> </span> |
169
|
|
|
|
|
|
|
</div> |
170
|
|
|
|
|
|
|
</div> |
171
|
|
|
|
|
|
|
EOF |
172
|
|
|
|
|
|
|
|
173
|
18
|
|
|
|
|
23
|
return $fieldset_template; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 NAME |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
HTML::FormBuilder::FieldSet - FieldSet container used by HTML::FormBuilder |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 SYNOPSIS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my $form = HTML::FormBuilder->new(data => {id => 'testform}); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
my $fieldset = $form->add_fieldset({id => 'fieldset1'}); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$fieldset->add_field({input => {type => 'text', value => 'Join'}}); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$form->add_field($fieldset_index, {input => {type => 'text', value => 'Join'}}); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 Attributes |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 fields |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The fields included by this fieldset. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 Methods |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 build |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my ($fieldset_group, $fieldset_html) = $fieldset->build(); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 add_field |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$fieldset->add_field({input => {type => 'text', value => 'name'}}); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
append the field into fieldset and return that field |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 add_fields |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
$fieldset->add_fields({input => {type => 'text', value => 'name'}},{input => {type => 'text', value => 'address'}}); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
append fields into fieldset and return the number of fields added. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 data |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 AUTHOR |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Chylli L<mailto:chylli@binary.com> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Fayland Lam L<mailto:fayland@binary.com> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Tee Shuwn Yuan L<mailto:shuwnyuan@binary.com> |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |