line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
8
|
|
|
8
|
|
101773
|
use warnings; |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
245
|
|
4
|
8
|
|
|
8
|
|
44
|
use 5.008_005; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
189
|
|
5
|
8
|
|
|
8
|
|
140
|
|
|
8
|
|
|
|
|
30
|
|
6
|
|
|
|
|
|
|
use Carp; |
7
|
8
|
|
|
8
|
|
49
|
use Moo; |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
449
|
|
8
|
8
|
|
|
8
|
|
53
|
use namespace::clean; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
46
|
|
9
|
8
|
|
|
8
|
|
3017
|
|
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
54
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.13'; ## VERSION |
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
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
my $element_tag = shift; |
58
|
275
|
|
|
275
|
|
866
|
my $attributes = shift; |
59
|
275
|
|
|
|
|
368
|
my $content = shift || ''; |
60
|
275
|
|
|
|
|
332
|
my $options = shift || {}; |
61
|
275
|
|
100
|
|
|
620
|
|
62
|
275
|
|
100
|
|
|
680
|
#check if the elemen tag is empty |
63
|
|
|
|
|
|
|
return if ($element_tag eq ''); |
64
|
|
|
|
|
|
|
|
65
|
275
|
50
|
|
|
|
593
|
my $html; |
66
|
|
|
|
|
|
|
$html = '<' . $element_tag; |
67
|
275
|
|
|
|
|
348
|
foreach my $key (sort keys %{$attributes}) { |
68
|
275
|
|
|
|
|
396
|
next |
69
|
275
|
|
|
|
|
369
|
if (ref($attributes->{$key}) eq 'HASH' |
|
275
|
|
|
|
|
981
|
|
70
|
|
|
|
|
|
|
or ref($attributes->{$key}) eq 'ARRAY'); |
71
|
|
|
|
|
|
|
|
72
|
665
|
100
|
66
|
|
|
1966
|
# skip attributes that are not intended for HTML |
73
|
|
|
|
|
|
|
next if ($key =~ /^(?:option|text|hide_required_text|localize|wrap_in_div_class)/i); |
74
|
|
|
|
|
|
|
next if not defined $attributes->{$key}; |
75
|
664
|
100
|
|
|
|
1660
|
next if $attributes->{$key} eq ''; |
76
|
558
|
100
|
|
|
|
995
|
|
77
|
541
|
100
|
|
|
|
934
|
$html .= qq[ $key="$attributes->{$key}"]; |
78
|
|
|
|
|
|
|
} |
79
|
531
|
|
|
|
|
1083
|
if ($element_tag eq 'button') { |
80
|
|
|
|
|
|
|
$html .= '>' . $attributes->{'value'} . '</' . $element_tag . '>'; |
81
|
275
|
100
|
|
|
|
602
|
} else { |
82
|
1
|
|
|
|
|
4
|
$html .= '>'; |
83
|
|
|
|
|
|
|
} |
84
|
274
|
|
|
|
|
391
|
|
85
|
|
|
|
|
|
|
if ($options->{required_mark} && !$self->{option}{hide_required_text}) { |
86
|
|
|
|
|
|
|
$html .= qq[<em class="$self->{classes}{required_asterisk}">**</em>]; |
87
|
275
|
100
|
66
|
|
|
592
|
} |
88
|
3
|
|
|
|
|
20
|
|
89
|
|
|
|
|
|
|
#close the tag |
90
|
|
|
|
|
|
|
my $end_tag = "</$element_tag>"; |
91
|
|
|
|
|
|
|
|
92
|
275
|
|
|
|
|
467
|
# input needn't close tag |
93
|
|
|
|
|
|
|
if ($element_tag =~ /^(input)$/) { |
94
|
|
|
|
|
|
|
$end_tag = ''; |
95
|
275
|
100
|
|
|
|
573
|
} |
96
|
52
|
|
|
|
|
90
|
return $html . $content . $end_tag; |
97
|
|
|
|
|
|
|
} |
98
|
275
|
|
|
|
|
1109
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
my $str = shift; |
109
|
|
|
|
|
|
|
return $self->localize->($str); |
110
|
8
|
|
|
8
|
|
955
|
} |
111
|
8
|
|
|
|
|
17
|
|
112
|
8
|
|
|
|
|
38
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
HTML::FormBuilder::Base - HTML::FormBuilder and HTML::FormBuilder::Fieldset, HTML::FormBuilder::Field base class |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 Attributes |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 classes |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
please refer to L<HTML::FormBuilder>. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 localize |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
please refer to L<HTML::FormBuilder>. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Chylli L<mailto:chylli@binary.com> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Fayland Lam L<mailto:fayland@binary.com> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Tee Shuwn Yuan L<mailto:shuwnyuan@binary.com> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |