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