line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Auto; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
41465
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
44
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1607
|
use Template; |
|
2
|
|
|
|
|
51837
|
|
|
2
|
|
|
|
|
69
|
|
7
|
2
|
|
|
2
|
|
1270
|
use HTML::Auto::Templates; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
55
|
|
8
|
2
|
|
|
2
|
|
2132
|
use Data::Dumper; |
|
2
|
|
|
|
|
13973
|
|
|
2
|
|
|
|
|
1195
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(matrix h v); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=encoding utf-8 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
HTML::Auto - automatic write HTML for common elements |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Version 0.06 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Simple example: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use HTML::Auto qw/matrix h v/; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @cols = qw/c1 c2 c3 c4 c5/; |
36
|
|
|
|
|
|
|
my @lines = qw/l1 l2 l3 l4 l5/; |
37
|
|
|
|
|
|
|
my $data = |
38
|
|
|
|
|
|
|
[ [1,2,3,4,5], |
39
|
|
|
|
|
|
|
[6,7,8,9,0], |
40
|
|
|
|
|
|
|
[1,1,1,1,1], |
41
|
|
|
|
|
|
|
[2,2,2,2,2], |
42
|
|
|
|
|
|
|
[3,3,3,3,3] ]; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
print v( |
47
|
|
|
|
|
|
|
h($m,$m,$m), |
48
|
|
|
|
|
|
|
h($m,$m), |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Using attributes: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use HTML::Auto qw/matrix h v/; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @cols = qw/c1 c2/; |
56
|
|
|
|
|
|
|
my @lines = qw/l1 l2/; |
57
|
|
|
|
|
|
|
my $data = |
58
|
|
|
|
|
|
|
[ |
59
|
|
|
|
|
|
|
[ |
60
|
|
|
|
|
|
|
{v => 1, a => { style => 'background: green'}}, |
61
|
|
|
|
|
|
|
2 |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
[ |
64
|
|
|
|
|
|
|
{v => 3, a => {class => 'foo'}}, |
65
|
|
|
|
|
|
|
{v => 4, a => {style => 'color: red'}} |
66
|
|
|
|
|
|
|
] |
67
|
|
|
|
|
|
|
]; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
print v( |
72
|
|
|
|
|
|
|
h($m) |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
With mouse-over span: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use HTML::Auto qw/matrix h v/; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my @cols = qw/c1 c2/; |
80
|
|
|
|
|
|
|
my @lines = qw/l1 l2/; |
81
|
|
|
|
|
|
|
my $data = |
82
|
|
|
|
|
|
|
[[1,2], |
83
|
|
|
|
|
|
|
[3, |
84
|
|
|
|
|
|
|
{ v=> 4, |
85
|
|
|
|
|
|
|
more_info => "This is a pop-up!" |
86
|
|
|
|
|
|
|
}] |
87
|
|
|
|
|
|
|
]; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
print v( |
93
|
|
|
|
|
|
|
h($m) |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Passing additional CSS: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use HTML::Auto qw/matrix h v/; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @cols = qw/c1 c2/; |
101
|
|
|
|
|
|
|
my @lines = qw/l1 l2/; |
102
|
|
|
|
|
|
|
my $data = |
103
|
|
|
|
|
|
|
[ |
104
|
|
|
|
|
|
|
[ |
105
|
|
|
|
|
|
|
{v => 1, a => { class => 'warn'}}, |
106
|
|
|
|
|
|
|
2 |
107
|
|
|
|
|
|
|
], |
108
|
|
|
|
|
|
|
[3,4] |
109
|
|
|
|
|
|
|
]; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $options = { css => '.warn { background-color: yellow !important; }' }; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data,$options); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
print v( |
116
|
|
|
|
|
|
|
h($m) |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 matrix |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub matrix { |
128
|
2
|
|
|
2
|
1
|
1977
|
my ($cols,$lines,$data,$options) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# pre-process data |
131
|
2
|
|
|
|
|
8
|
foreach (@$cols) { |
132
|
4
|
|
|
|
|
18
|
$_ = ucfirst($_); |
133
|
|
|
|
|
|
|
} |
134
|
2
|
|
|
|
|
7
|
foreach (@$lines) { |
135
|
4
|
|
|
|
|
37
|
$_ = ucfirst($_); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
5
|
my $vals = []; |
139
|
2
|
|
|
|
|
5
|
my $attrs = []; |
140
|
2
|
|
|
|
|
6
|
my $more = []; |
141
|
|
|
|
|
|
|
|
142
|
2
|
|
|
|
|
7
|
foreach my $row (@$data){ |
143
|
4
|
|
|
|
|
8
|
my $vrow = []; |
144
|
4
|
|
|
|
|
8
|
my $arow = []; |
145
|
4
|
|
|
|
|
8
|
my $mrow = []; |
146
|
4
|
|
|
|
|
10
|
foreach(@$row){ |
147
|
8
|
100
|
|
|
|
25
|
if (ref($_)){ |
148
|
1
|
|
|
|
|
4
|
push @$vrow, $_->{v}; |
149
|
1
|
|
|
|
|
4
|
push @$arow, $_->{a}; |
150
|
1
|
|
|
|
|
5
|
push @$mrow, $_->{more_info}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else { |
153
|
7
|
|
|
|
|
11
|
push @$vrow, $_; |
154
|
7
|
|
|
|
|
13
|
push @$arow, undef; |
155
|
7
|
|
|
|
|
19
|
push @$mrow, undef; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
4
|
|
|
|
|
8
|
push @$vals, $vrow; |
159
|
4
|
|
|
|
|
7
|
push @$attrs, $arow; |
160
|
4
|
|
|
|
|
14
|
push @$more, $mrow; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
97
|
my $vars = { |
164
|
|
|
|
|
|
|
cols => $cols, |
165
|
|
|
|
|
|
|
lines => $lines, |
166
|
|
|
|
|
|
|
vals => $vals, |
167
|
|
|
|
|
|
|
attrs => $attrs, |
168
|
|
|
|
|
|
|
more => $more, |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
$vars->{css} = $options->{css} |
171
|
2
|
50
|
|
|
|
15
|
if $options->{css}; |
172
|
2
|
|
|
|
|
5
|
my $template_name = 'matrix'; |
173
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
8
|
__process($template_name, $vars); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 h |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
A function to allow horizontal composition. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub h { |
184
|
1
|
|
|
1
|
1
|
1481
|
my (@list) = @_; |
185
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
6
|
my $vars = { |
187
|
|
|
|
|
|
|
list => [@list], |
188
|
|
|
|
|
|
|
}; |
189
|
1
|
|
|
|
|
3
|
my $template_name = 'h'; |
190
|
|
|
|
|
|
|
|
191
|
1
|
|
|
|
|
6
|
__process($template_name, $vars); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 v |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
A function to allow vertical composition. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub v { |
201
|
1
|
|
|
1
|
1
|
75
|
my (@list) = @_; |
202
|
|
|
|
|
|
|
|
203
|
1
|
|
|
|
|
5
|
my $vars = { |
204
|
|
|
|
|
|
|
list => [@list], |
205
|
|
|
|
|
|
|
}; |
206
|
1
|
|
|
|
|
2
|
my $template_name = 'v'; |
207
|
|
|
|
|
|
|
|
208
|
1
|
|
|
|
|
5
|
__process($template_name, $vars); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub __process { |
212
|
4
|
|
|
4
|
|
8
|
my ($template_name,$vars) = @_; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# build html from template |
215
|
4
|
|
|
|
|
18
|
my $template_config = { |
216
|
|
|
|
|
|
|
INCLUDE_PATH => [ 'templates' ], |
217
|
|
|
|
|
|
|
}; |
218
|
4
|
|
|
|
|
55
|
my $template = Template->new({ |
219
|
|
|
|
|
|
|
LOAD_TEMPLATES => [ HTML::Auto::Templates->new($template_config) ], |
220
|
|
|
|
|
|
|
}); |
221
|
4
|
|
|
|
|
27770
|
my $html; |
222
|
4
|
|
|
|
|
18
|
$template->process($template_name, $vars, \$html); |
223
|
|
|
|
|
|
|
|
224
|
4
|
|
|
|
|
636509
|
$html; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 AUTHOR |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Nuno Carvalho, C<< >> |
230
|
|
|
|
|
|
|
André Santos, C<< >> |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 BUGS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
235
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
236
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 SUPPORT |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
perldoc HTML::Auto |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
You can also look for information at: |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=over 4 |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
L |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
L |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item * CPAN Ratings |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item * Search CPAN |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
L |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=back |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Copyright 2012 Project Natura. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
279
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
280
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
1; # End of HTML::Auto |