line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Accessors; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1240
|
use 5.01; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
15
|
use version; our $VERSION = qv( sprintf '0.12.%d', q$Rev: 1 $ =~ /\d+/gmx ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
134
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
101
|
|
9
|
1
|
|
|
1
|
|
1089
|
use HTML::GenerateUtil qw( generate_tag :consts ); |
|
1
|
|
|
|
|
2205
|
|
|
1
|
|
|
|
|
235
|
|
10
|
1
|
|
|
1
|
|
8014
|
use HTML::Tagset; |
|
1
|
|
|
|
|
4941
|
|
|
1
|
|
|
|
|
2933
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $INP = { checkbox => 'checkbox', |
13
|
|
|
|
|
|
|
hidden => 'hidden', |
14
|
|
|
|
|
|
|
image_button => 'image', |
15
|
|
|
|
|
|
|
password_field => 'password', |
16
|
|
|
|
|
|
|
radio_button => 'radio', |
17
|
|
|
|
|
|
|
submit => 'submit', |
18
|
|
|
|
|
|
|
textfield => 'text' }; |
19
|
|
|
|
|
|
|
my $NUL = q(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
3
|
|
66
|
3
|
1
|
3607
|
my ($self, @args) = @_; my $class = ref $self || $self; |
|
3
|
|
|
|
|
33
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
|
|
16
|
my $attr = { content_type => 'application/xhtml+xml' }; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
16
|
return bless _hash_merge( $attr, _arg_list( @args ) ), $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub content_type { |
30
|
14
|
|
|
14
|
1
|
103
|
return $_[ 0 ]->{content_type}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub escape_html { |
34
|
1
|
|
|
1
|
1
|
599
|
my ($self, @args) = @_; return HTML::GenerateUtil::escape_html( @args ); |
|
1
|
|
|
|
|
15
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub is_xml { |
38
|
14
|
100
|
|
14
|
1
|
37
|
return $_[ 0 ]->content_type =~ m{ / (.*) xml \z }mx ? 1 : 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub popup_menu { |
42
|
5
|
|
|
5
|
1
|
2305
|
my ($self, @args) = @_; my $options; |
|
5
|
|
|
|
|
7
|
|
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
12
|
my $args = _arg_list( @args ); |
45
|
5
|
|
100
|
|
|
26
|
my $classes = delete $args->{classes} || {}; |
46
|
5
|
|
66
|
|
|
26
|
my $def = delete $args->{default} || $NUL; |
47
|
5
|
|
100
|
|
|
20
|
my $labels = delete $args->{labels } || {}; |
48
|
5
|
|
100
|
|
|
33
|
my $values = delete $args->{values } || []; |
49
|
|
|
|
|
|
|
|
50
|
5
|
|
|
|
|
7
|
for my $val (grep { defined } @{ $values }) { |
|
4
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
13
|
|
51
|
4
|
100
|
|
|
|
15
|
my $opt_attr = $val eq $def ? { selected => $self->is_xml |
|
|
100
|
|
|
|
|
|
52
|
|
|
|
|
|
|
? 'selected' : undef } : {}; |
53
|
|
|
|
|
|
|
|
54
|
4
|
50
|
|
|
|
11
|
exists $classes->{ $val } and $opt_attr->{class} = $classes->{ $val }; |
55
|
|
|
|
|
|
|
|
56
|
4
|
100
|
|
|
|
11
|
if (exists $labels->{ $val }) { |
57
|
2
|
|
|
|
|
5
|
$opt_attr->{value} = $val; $val = $labels->{ $val }; |
|
2
|
|
|
|
|
4
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
29
|
$options .= generate_tag( 'option', $opt_attr, $val, GT_ADDNEWLINE ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
100
|
|
|
|
12
|
if ($options) { $options = "\n".$options } |
|
2
|
|
|
|
|
6
|
|
64
|
3
|
|
|
|
|
15
|
else { $options = generate_tag( 'option', undef, $NUL, GT_ADDNEWLINE ) } |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
55
|
return generate_tag( 'select', $args, $options, GT_ADDNEWLINE ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub radio_group { |
70
|
5
|
|
|
5
|
1
|
5755
|
my ($self, @args) = @_; |
71
|
|
|
|
|
|
|
|
72
|
5
|
|
|
|
|
24
|
my $args = _arg_list( @args ); |
73
|
5
|
|
100
|
|
|
171
|
my $cols = $args->{columns } || '999999'; |
74
|
5
|
|
100
|
|
|
25
|
my $def = $args->{default } || 0; |
75
|
5
|
|
100
|
|
|
16
|
my $labels = $args->{labels } || {}; |
76
|
5
|
|
100
|
|
|
19
|
my $label_class = $args->{label_class} || 'radio_group_label'; |
77
|
5
|
|
100
|
|
|
137
|
my $name = $args->{name } || 'radio'; |
78
|
5
|
|
100
|
|
|
18
|
my $values = $args->{values } || []; |
79
|
5
|
|
|
|
|
17
|
my $inp_attr = { name => $name, type => 'radio' }; |
80
|
5
|
100
|
|
|
|
14
|
my $mode = $self->is_xml ? GT_CLOSETAG : 0; |
81
|
5
|
|
|
|
|
10
|
my $html = $NUL; |
82
|
5
|
|
|
|
|
7
|
my $i = 1; |
83
|
|
|
|
|
|
|
|
84
|
5
|
50
|
|
|
|
13
|
$args->{onchange} and $inp_attr->{onchange} = $args->{onchange}; |
85
|
|
|
|
|
|
|
|
86
|
5
|
|
|
|
|
8
|
for my $val (grep { defined } @{ $values }) { |
|
32
|
|
|
|
|
53
|
|
|
5
|
|
|
|
|
12
|
|
87
|
32
|
|
|
|
|
48
|
$inp_attr->{value } = $val; |
88
|
32
|
|
|
|
|
38
|
$inp_attr->{tabindex} = $i; |
89
|
|
|
|
|
|
|
$val =~ m{ \d+ }mx and $def =~ m{ \d+ }mx and $val == $def |
90
|
32
|
100
|
100
|
|
|
156
|
and $inp_attr->{checked } = $self->is_xml ? 'checked' : undef; |
|
|
100
|
100
|
|
|
|
|
91
|
|
|
|
|
|
|
($val !~ m{ \d+ }mx or $def !~ m{ \d+ }mx) and $val eq $def |
92
|
32
|
100
|
100
|
|
|
179
|
and $inp_attr->{checked } = $self->is_xml ? 'checked' : undef; |
|
|
100
|
100
|
|
|
|
|
93
|
32
|
|
|
|
|
212
|
$html .= generate_tag( 'input', $inp_attr, undef, $mode ); |
94
|
32
|
100
|
100
|
|
|
458
|
(exists $labels->{ $val } and not defined $labels->{ $val }) |
|
|
|
100
|
|
|
|
|
95
|
|
|
|
|
|
|
or $html .= generate_tag( 'label', |
96
|
|
|
|
|
|
|
{ class => $label_class }, |
97
|
|
|
|
|
|
|
($labels->{ $val } || $val), |
98
|
|
|
|
|
|
|
GT_ADDNEWLINE ); |
99
|
32
|
100
|
|
|
|
118
|
$i % $cols == 0 and $html .= generate_tag( 'br', undef, undef, $mode ); |
100
|
32
|
|
|
|
|
54
|
delete $inp_attr->{checked}; |
101
|
32
|
|
|
|
|
43
|
$i++; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
5
|
|
|
|
|
34
|
return $html; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub scrolling_list { |
108
|
1
|
|
|
1
|
1
|
5
|
my ($self, @args) = @_; my $args = _arg_list( @args ); |
|
1
|
|
|
|
|
3
|
|
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
3
|
$args->{multiple} = 'multiple'; |
111
|
1
|
|
|
|
|
4
|
return $self->popup_menu( $args ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub AUTOLOAD { ## no critic |
115
|
7
|
|
|
7
|
|
549
|
my ($self, @args) = @_; my $args = {}; |
|
7
|
|
|
|
|
14
|
|
116
|
|
|
|
|
|
|
|
117
|
7
|
|
|
|
|
13
|
my $mode = GT_ADDNEWLINE; my $val = $args[ 0 ]; |
|
7
|
|
|
|
|
9
|
|
118
|
|
|
|
|
|
|
|
119
|
7
|
|
|
|
|
45
|
(my $elem = lc $HTML::Accessors::AUTOLOAD) =~ s{ .* :: }{}mx; |
120
|
|
|
|
|
|
|
|
121
|
7
|
100
|
100
|
|
|
43
|
if ($val and ref $val eq 'HASH') { $args = { %{ $val } }; $val = $args[ 1 ] } |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
7
|
|
122
|
|
|
|
|
|
|
|
123
|
7
|
100
|
|
|
|
21
|
if (exists $INP->{ $elem }) { |
124
|
3
|
|
|
|
|
31
|
$args->{type} = $INP->{ $elem }; |
125
|
3
|
100
|
|
|
|
15
|
defined $args->{default} and $args->{value} = delete $args->{default}; |
126
|
3
|
100
|
|
|
|
10
|
defined $args->{value } or $args->{value} = $NUL; |
127
|
3
|
|
|
|
|
6
|
$elem = 'input'; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
7
|
100
|
|
|
|
20
|
unless ($HTML::Tagset::isKnown{ $elem }) { ## no critic |
131
|
1
|
|
|
|
|
204
|
carp "Unknown element $elem"; return; |
|
1
|
|
|
|
|
159
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
6
|
|
33
|
|
|
37
|
$val //= delete $args->{default} // $NUL; |
|
|
|
66
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
6
|
100
|
|
|
|
26
|
if ($HTML::Tagset::emptyElement{ $elem }) { ## no critic |
137
|
3
|
100
|
|
|
|
3
|
$val = undef; $mode = $self->is_xml ? GT_CLOSETAG : 0; |
|
3
|
|
|
|
|
9
|
|
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
6
|
|
|
|
|
79
|
return generate_tag( $elem, $args, $val, $mode ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
1
|
|
8
|
sub DESTROY {} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Private subroutines |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _arg_list { |
148
|
14
|
100
|
|
14
|
|
67
|
return $_[ 0 ] ? ref $_[ 0 ] eq 'HASH' ? { %{ $_[ 0 ] } } : { @_ } : {}; |
|
7
|
100
|
|
|
|
42
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _hash_merge { |
152
|
3
|
50
|
|
3
|
|
7
|
return { %{ $_[ 0 ] }, %{ $_[ 1 ] || {} } }; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
45
|
|
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |