line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormBuilder::Base; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
44501
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
182
|
|
4
|
8
|
|
|
8
|
|
26
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
142
|
|
5
|
8
|
|
|
8
|
|
111
|
use 5.008_005; |
|
8
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
29
|
use Carp; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
339
|
|
8
|
8
|
|
|
8
|
|
28
|
use Moo; |
|
8
|
|
|
|
|
4
|
|
|
8
|
|
|
|
|
32
|
|
9
|
8
|
|
|
8
|
|
1598
|
use namespace::clean; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
55
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.12'; ## VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $CLASSES = { |
14
|
|
|
|
|
|
|
fieldset_group => 'fieldset_group', |
15
|
|
|
|
|
|
|
no_stack_field_parent => 'no_stack_field_parent', |
16
|
|
|
|
|
|
|
row_padding => 'row_padding', |
17
|
|
|
|
|
|
|
fieldset_footer => 'fieldset_footer', |
18
|
|
|
|
|
|
|
comment => 'comment', |
19
|
|
|
|
|
|
|
row => 'row', |
20
|
|
|
|
|
|
|
extra_tooltip_container => 'extra_tooltip_container', |
21
|
|
|
|
|
|
|
backbutton => 'backbutton', |
22
|
|
|
|
|
|
|
required_asterisk => 'required_asterisk', |
23
|
|
|
|
|
|
|
inputtrailing => 'inputtrailing', |
24
|
|
|
|
|
|
|
label_column => 'label_column', |
25
|
|
|
|
|
|
|
input_column => 'input_column', |
26
|
|
|
|
|
|
|
hide_mobile => 'hide_mobile' |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has classes => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => sub { |
32
|
|
|
|
|
|
|
my $classes = shift; |
33
|
|
|
|
|
|
|
croak('classes should be a hashref') unless ref($classes) eq 'HASH'; |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has localize => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => sub { |
39
|
|
|
|
|
|
|
my $localize = shift; |
40
|
|
|
|
|
|
|
croak('localize should be a sub') unless ref($localize) eq 'CODE'; |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
default => sub { |
43
|
|
|
|
|
|
|
return sub { return shift; } |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
##################################################################### |
48
|
|
|
|
|
|
|
# Usage : build the html element and its own attributes |
49
|
|
|
|
|
|
|
# Purpose : perform checking and drop unnecessary attributes |
50
|
|
|
|
|
|
|
# Returns : element with its attributes in string |
51
|
|
|
|
|
|
|
# Parameters : $element_tag such as p, input, label and etc |
52
|
|
|
|
|
|
|
# $attributes in HASH ref for example |
53
|
|
|
|
|
|
|
# $attributes = {'id' => 'test', 'name' => 'test', 'class' => 'myclass'} |
54
|
|
|
|
|
|
|
# Comments : |
55
|
|
|
|
|
|
|
# See Also : |
56
|
|
|
|
|
|
|
##################################################################### |
57
|
|
|
|
|
|
|
sub _build_element_and_attributes { |
58
|
275
|
|
|
275
|
|
536
|
my $self = shift; |
59
|
275
|
|
|
|
|
174
|
my $element_tag = shift; |
60
|
275
|
|
|
|
|
179
|
my $attributes = shift; |
61
|
275
|
|
100
|
|
|
447
|
my $content = shift || ''; |
62
|
275
|
|
100
|
|
|
566
|
my $options = shift || {}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#check if the elemen tag is empty |
65
|
275
|
50
|
|
|
|
352
|
return if ($element_tag eq ''); |
66
|
|
|
|
|
|
|
|
67
|
275
|
|
|
|
|
164
|
my $html; |
68
|
275
|
|
|
|
|
194
|
$html = '<' . $element_tag; |
69
|
275
|
|
|
|
|
214
|
foreach my $key (sort keys %{$attributes}) { |
|
275
|
|
|
|
|
645
|
|
70
|
|
|
|
|
|
|
next |
71
|
|
|
|
|
|
|
if (ref($attributes->{$key}) eq 'HASH' |
72
|
665
|
100
|
66
|
|
|
1723
|
or ref($attributes->{$key}) eq 'ARRAY'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# skip attributes that are not intended for HTML |
75
|
664
|
100
|
|
|
|
1053
|
next if ($key =~ /^(?:option|text|hide_required_text|localize|wrap_in_div_class)/i); |
76
|
558
|
100
|
|
|
|
679
|
if ($attributes->{$key}) { |
77
|
530
|
|
|
|
|
668
|
$html .= ' ' . $key . '="' . $attributes->{$key} . '"'; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
275
|
100
|
|
|
|
324
|
if ($element_tag eq 'button') { |
81
|
1
|
|
|
|
|
2
|
$html .= '>' . $attributes->{'value'} . '</' . $element_tag . '>'; |
82
|
|
|
|
|
|
|
} else { |
83
|
274
|
|
|
|
|
206
|
$html .= '>'; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
275
|
100
|
66
|
|
|
420
|
if ($options->{required_mark} && !$self->{option}{hide_required_text}) { |
87
|
3
|
|
|
|
|
9
|
$html .= qq[<em class="$self->{classes}{required_asterisk}">**</em>]; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#close the tag |
91
|
275
|
|
|
|
|
283
|
my $end_tag = "</$element_tag>"; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# input needn't close tag |
94
|
275
|
100
|
|
|
|
395
|
if ($element_tag =~ /^(input)$/) { |
95
|
52
|
|
|
|
|
45
|
$end_tag = ''; |
96
|
|
|
|
|
|
|
} |
97
|
275
|
|
|
|
|
789
|
return $html . $content . $end_tag; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
##################################################################### |
101
|
|
|
|
|
|
|
# Usage : call $self->{option}{localize} to localize a string |
102
|
|
|
|
|
|
|
# Purpose : localize string |
103
|
|
|
|
|
|
|
# Returns : a localized string |
104
|
|
|
|
|
|
|
# Parameters : string |
105
|
|
|
|
|
|
|
# Comments : |
106
|
|
|
|
|
|
|
# See Also : new |
107
|
|
|
|
|
|
|
##################################################################### |
108
|
|
|
|
|
|
|
sub _localize { |
109
|
8
|
|
|
8
|
|
608
|
my $self = shift; |
110
|
8
|
|
|
|
|
11
|
my $str = shift; |
111
|
8
|
|
|
|
|
27
|
return $self->localize->($str); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
HTML::FormBuilder::Base - HTML::FormBuilder and HTML::FormBuilder::Fieldset, HTML::FormBuilder::Field base class |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 Attributes |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 classes |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
please refer to L<HTML::FormBuilder>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 localize |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
please refer to L<HTML::FormBuilder>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Chylli L<mailto:chylli@binary.com> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Fayland Lam L<mailto:fayland@binary.com> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Tee Shuwn Yuan L<mailto:shuwnyuan@binary.com> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |