| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::Table::HTML; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
913213
|
use 5.010001; |
|
|
4
|
|
|
|
|
43
|
|
|
4
|
4
|
|
|
4
|
|
24
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
77
|
|
|
5
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
2378
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
8
|
|
|
|
|
|
|
our $DATE = '2023-05-22'; # DATE |
|
9
|
|
|
|
|
|
|
our $DIST = 'Text-Table-HTML'; # DIST |
|
10
|
|
|
|
|
|
|
our $VERSION = '0.010'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _encode { |
|
13
|
42
|
|
|
42
|
|
77
|
state $load = do { require HTML::Entities }; |
|
|
4
|
|
|
|
|
2328
|
|
|
14
|
42
|
|
|
|
|
23003
|
HTML::Entities::encode_entities(shift); |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub table { |
|
18
|
11
|
|
|
11
|
1
|
455
|
my %params = @_; |
|
19
|
11
|
50
|
|
|
|
45
|
my $rows = $params{rows} or die "Must provide rows!"; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# here we go... |
|
22
|
11
|
|
|
|
|
21
|
my @table; |
|
23
|
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
22
|
push @table, "\n";
|
25
|
|
|
|
|
|
|
|
|
26
|
11
|
100
|
|
|
|
34
|
if (defined $params{caption}) { |
|
27
|
1
|
|
|
|
|
4
|
push @table, ""._encode($params{caption})."\n"; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# then the data |
|
31
|
11
|
|
100
|
|
|
76
|
my $header_row = $params{header_row} // 0; |
|
32
|
11
|
|
|
|
|
21
|
my $needs_thead = !!$header_row; |
|
33
|
11
|
|
|
|
|
21
|
my $needs_tbody = !!1; |
|
34
|
11
|
|
|
|
|
18
|
foreach my $row ( @{$rows} ) { |
|
|
11
|
|
|
|
|
26
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
23
|
|
|
|
|
35
|
my $coltag = 'td'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
23
|
100
|
|
|
|
66
|
if ($header_row ) { |
|
|
|
100
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
6
|
$coltag = 'th'; |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
100
|
|
|
|
6
|
if ($needs_thead) { |
|
42
|
2
|
|
|
|
|
5
|
push @table, "\n";
|
43
|
2
|
|
|
|
|
2
|
$needs_thead = !!0; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
elsif ($needs_tbody) { |
|
48
|
10
|
|
|
|
|
17
|
push @table, " | | \n";
|
49
|
10
|
|
|
|
|
19
|
$needs_tbody = !!0; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
23
|
|
|
|
|
35
|
my $bottom_border; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my @row; |
|
55
|
|
|
|
|
|
|
|
|
56
|
23
|
|
|
|
|
41
|
for my $cell (@$row) { |
|
57
|
|
|
|
|
|
|
|
|
58
|
42
|
|
|
|
|
61
|
my $text; |
|
59
|
42
|
|
|
|
|
58
|
my $attr = ''; |
|
60
|
|
|
|
|
|
|
|
|
61
|
42
|
100
|
|
|
|
89
|
if (ref $cell eq 'HASH') { |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# add a class attribute for bottom_border if |
|
64
|
|
|
|
|
|
|
# any cell in the row has it set. once the attribute is set, |
|
65
|
|
|
|
|
|
|
# no need to do the check again. |
|
66
|
|
|
|
|
|
|
$bottom_border //= |
|
67
|
8
|
|
100
|
|
|
63
|
($cell->{bottom_border} || undef) && " class=has_bottom_border"; |
|
|
|
|
66
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
8
|
100
|
|
|
|
40
|
if (defined $cell->{raw_html}) { |
|
70
|
1
|
|
|
|
|
3
|
$text = $cell->{raw_html}; |
|
71
|
|
|
|
|
|
|
} else { |
|
72
|
7
|
|
50
|
|
|
23
|
$text = _encode( $cell->{text} // '' ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
8
|
|
100
|
|
|
147
|
my $rowspan = int($cell->{rowspan} // 1); |
|
76
|
8
|
100
|
|
|
|
25
|
$attr .= " rowspan=$rowspan" if $rowspan > 1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
8
|
|
100
|
|
|
29
|
my $colspan = int($cell->{colspan} // 1); |
|
79
|
8
|
100
|
|
|
|
39
|
$attr .= " colspan=$colspan" if $colspan > 1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
8
|
50
|
|
|
|
30
|
$attr .= ' align="' . $cell->{align} . '"' if defined $cell->{align}; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
else { |
|
84
|
34
|
|
50
|
|
|
77
|
$text = _encode( $cell // '' ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
42
|
|
|
|
|
551
|
push @row, |
|
88
|
|
|
|
|
|
|
'<' . $coltag . $attr . '>', $text, '' . $coltag . '>'; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
23
|
|
100
|
|
|
117
|
push @table, |
|
92
|
|
|
|
|
|
|
" | ",
|
93
|
|
|
|
|
|
|
@row, |
|
94
|
|
|
|
|
|
|
" | \n";
|
95
|
|
|
|
|
|
|
|
|
96
|
23
|
100
|
100
|
|
|
82
|
if ( $header_row && $header_row-- == 1 ) { |
|
97
|
2
|
|
|
|
|
5
|
push @table, "\n"; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
11
|
100
|
|
|
|
32
|
push @table, " | \n" if $needs_tbody;
|
102
|
11
|
|
|
|
|
23
|
push @table, " | \n";
|
103
|
11
|
|
|
|
|
20
|
push @table, " | \n"; |
|
104
|
|
|
|
|
|
|
|
|
105
|
11
|
|
|
|
|
21
|
return join("", grep {$_} @table); |
|
|
221
|
|
|
|
|
402
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
|
109
|
|
|
|
|
|
|
# ABSTRACT: Generate HTML table |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |