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