line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Auto; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
27918
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
992
|
use Template; |
|
2
|
|
|
|
|
32288
|
|
|
2
|
|
|
|
|
52
|
|
7
|
2
|
|
|
2
|
|
828
|
use HTML::Auto::Templates; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
8
|
2
|
|
|
2
|
|
1087
|
use Data::Dumper; |
|
2
|
|
|
|
|
9677
|
|
|
2
|
|
|
|
|
827
|
|
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.07 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
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 FUNCTIONS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 matrix |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Build a matrix. Some options are available to pass to the matrix function: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 6 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item C |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Highlight the diagonal of the matrix. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data, {diagonal => 1}); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item C |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Pass a string to be used by the C filter in the TT2 template. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data, {format => '%.6f'}); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item C |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Option to uppercase first letter in columns and lines labels. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $m = matrix(\@cols,\@lines,$data, {ucfirst => 1}); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub matrix { |
152
|
3
|
|
|
3
|
1
|
70568
|
my ($cols,$lines,$data,$options) = @_; |
153
|
|
|
|
|
|
|
|
154
|
3
|
50
|
|
|
|
14
|
if ($options->{ucfirst}) { |
155
|
0
|
|
|
|
|
0
|
foreach (@$cols) { |
156
|
0
|
|
|
|
|
0
|
$_ = ucfirst($_); |
157
|
|
|
|
|
|
|
} |
158
|
0
|
|
|
|
|
0
|
foreach (@$lines) { |
159
|
0
|
|
|
|
|
0
|
$_ = ucfirst($_); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
3
|
|
|
|
|
6
|
my $vals = []; |
164
|
3
|
|
|
|
|
8
|
my $attrs = []; |
165
|
3
|
|
|
|
|
3
|
my $more = []; |
166
|
|
|
|
|
|
|
|
167
|
3
|
|
|
|
|
10
|
foreach my $row (@$data){ |
168
|
6
|
|
|
|
|
6
|
my $vrow = []; |
169
|
6
|
|
|
|
|
5
|
my $arow = []; |
170
|
6
|
|
|
|
|
9
|
my $mrow = []; |
171
|
6
|
|
|
|
|
6
|
foreach(@$row){ |
172
|
12
|
100
|
|
|
|
18
|
if (ref($_)){ |
173
|
1
|
|
|
|
|
1
|
push @$vrow, $_->{v}; |
174
|
1
|
|
|
|
|
2
|
push @$arow, $_->{a}; |
175
|
1
|
|
|
|
|
2
|
push @$mrow, $_->{more_info}; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
else { |
178
|
11
|
|
|
|
|
12
|
push @$vrow, $_; |
179
|
11
|
|
|
|
|
9
|
push @$arow, undef; |
180
|
11
|
|
|
|
|
15
|
push @$mrow, undef; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
6
|
|
|
|
|
7
|
push @$vals, $vrow; |
184
|
6
|
|
|
|
|
6
|
push @$attrs, $arow; |
185
|
6
|
|
|
|
|
19
|
push @$more, $mrow; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
3
|
|
|
|
|
16
|
my $vars = { |
189
|
|
|
|
|
|
|
cols => $cols, |
190
|
|
|
|
|
|
|
lines => $lines, |
191
|
|
|
|
|
|
|
vals => $vals, |
192
|
|
|
|
|
|
|
attrs => $attrs, |
193
|
|
|
|
|
|
|
more => $more, |
194
|
|
|
|
|
|
|
}; |
195
|
|
|
|
|
|
|
$vars->{css} = $options->{css} |
196
|
3
|
50
|
|
|
|
10
|
if $options->{css}; |
197
|
|
|
|
|
|
|
$vars->{myformat} = $options->{format} |
198
|
3
|
50
|
|
|
|
8
|
if $options->{format}; |
199
|
|
|
|
|
|
|
$vars->{diagonal} = $options->{diagonal} |
200
|
3
|
100
|
|
|
|
11
|
if $options->{diagonal}; |
201
|
|
|
|
|
|
|
|
202
|
3
|
|
|
|
|
4
|
my $template_name = 'matrix'; |
203
|
3
|
|
|
|
|
7
|
__process($template_name, $vars); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 h |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
A function to allow horizontal composition. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub h { |
213
|
1
|
|
|
1
|
1
|
734
|
my (@list) = @_; |
214
|
|
|
|
|
|
|
|
215
|
1
|
|
|
|
|
3
|
my $vars = { |
216
|
|
|
|
|
|
|
list => [@list], |
217
|
|
|
|
|
|
|
}; |
218
|
1
|
|
|
|
|
3
|
my $template_name = 'h'; |
219
|
|
|
|
|
|
|
|
220
|
1
|
|
|
|
|
3
|
__process($template_name, $vars); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 v |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
A function to allow vertical composition. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub v { |
230
|
1
|
|
|
1
|
1
|
805
|
my (@list) = @_; |
231
|
|
|
|
|
|
|
|
232
|
1
|
|
|
|
|
17
|
my $vars = { |
233
|
|
|
|
|
|
|
list => [@list], |
234
|
|
|
|
|
|
|
}; |
235
|
1
|
|
|
|
|
4
|
my $template_name = 'v'; |
236
|
|
|
|
|
|
|
|
237
|
1
|
|
|
|
|
4
|
__process($template_name, $vars); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub __process { |
241
|
5
|
|
|
5
|
|
8
|
my ($template_name,$vars) = @_; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# build html from template |
244
|
5
|
|
|
|
|
13
|
my $template_config = { |
245
|
|
|
|
|
|
|
INCLUDE_PATH => [ 'templates' ], |
246
|
|
|
|
|
|
|
}; |
247
|
5
|
|
|
|
|
49
|
my $template = Template->new({ |
248
|
|
|
|
|
|
|
LOAD_TEMPLATES => [ HTML::Auto::Templates->new($template_config) ], |
249
|
|
|
|
|
|
|
}); |
250
|
5
|
|
|
|
|
19196
|
my $html; |
251
|
5
|
|
|
|
|
19
|
$template->process($template_name, $vars, \$html); |
252
|
|
|
|
|
|
|
|
253
|
5
|
|
|
|
|
6133
|
$html; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 AUTHOR |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Nuno Carvalho, C<< >> |
259
|
|
|
|
|
|
|
André Santos, C<< >> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 BUGS |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
264
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
265
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 SUPPORT |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
perldoc HTML::Auto |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
You can also look for information at: |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=over 4 |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
L |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
L |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * CPAN Ratings |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * Search CPAN |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
L |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=back |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Copyright 2012 Project Natura. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
308
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
309
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
1; # End of HTML::Auto |