| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::TableTiler ; |
|
2
|
|
|
|
|
|
|
$VERSION = 1.21 ; |
|
3
|
4
|
|
|
4
|
|
115115
|
use strict ; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
153
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# This file uses the "Perlish" coding style |
|
6
|
|
|
|
|
|
|
# please read http://perl.4pro.net/perlish_coding_style.html |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
; use 5.005 |
|
9
|
4
|
|
|
4
|
|
100
|
; use Carp |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
133
|
|
|
10
|
4
|
|
|
4
|
|
22
|
; use HTML::PullParser 1.0 |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
398
|
|
|
11
|
4
|
|
|
4
|
|
3832
|
; use IO::Util 1.2 |
|
|
4
|
|
|
|
|
34744
|
|
|
|
4
|
|
|
|
|
176
|
|
|
12
|
4
|
|
|
4
|
|
4257
|
; require Exporter |
|
|
4
|
|
|
|
|
13408
|
|
|
|
4
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
|
|
; @HTML::TableTiler::ISA = qw| Exporter | |
|
14
|
|
|
|
|
|
|
; @HTML::TableTiler::EXPORT_OK = qw| tile_table | |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
; BEGIN |
|
17
|
|
|
|
|
|
|
{ *PULL = sub () { 'PULL' } |
|
18
|
4
|
|
|
4
|
|
1670
|
; *TILE = sub () { 'TILE' } |
|
19
|
4
|
|
|
|
|
10
|
; *TRIM = sub () { 'TRIM' } |
|
20
|
4
|
|
|
|
|
10
|
; *TRUE = sub () { 1 } |
|
21
|
4
|
|
|
|
|
11
|
; *FALSE = sub () { 0 } |
|
22
|
4
|
|
|
|
|
7
|
; *RESET = sub () { 0 } |
|
23
|
4
|
|
|
|
|
5393
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
; sub new |
|
26
|
4
|
|
|
4
|
1
|
65
|
{ my $c = shift |
|
27
|
4
|
|
100
|
|
|
28
|
; my $t = shift || \ '' |
|
28
|
4
|
100
|
|
|
|
36
|
; $t = IO::Util::slurp($t) |
|
29
|
|
|
|
|
|
|
unless ref $t eq 'SCALAR' |
|
30
|
4
|
50
|
|
|
|
169
|
; $$t or croak 'The tile content is empty' |
|
31
|
4
|
|
|
|
|
18
|
; my $s = _parse_table($t) |
|
32
|
4
|
|
|
|
|
19
|
; bless $s, $c |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
; sub _parse_table |
|
36
|
4
|
|
|
4
|
|
10
|
{ my ( $content ) = shift |
|
37
|
4
|
|
|
|
|
49
|
; my ( $start |
|
38
|
|
|
|
|
|
|
, $Hrows |
|
39
|
|
|
|
|
|
|
, $end |
|
40
|
|
|
|
|
|
|
) |
|
41
|
|
|
|
|
|
|
= $$content =~ m| ^ |
|
42
|
|
|
|
|
|
|
(.*?) # start |
|
43
|
|
|
|
|
|
|
( |
]*?> .*
) # Hrows
|
44
|
|
|
|
|
|
|
(.*) # end |
|
45
|
|
|
|
|
|
|
$ |
|
46
|
|
|
|
|
|
|
|xsi |
|
47
|
4
|
|
|
|
|
9
|
; my ( $p |
|
48
|
|
|
|
|
|
|
, $rows |
|
49
|
|
|
|
|
|
|
, $ignore |
|
50
|
|
|
|
|
|
|
) |
|
51
|
4
|
50
|
|
|
|
16
|
; $Hrows or croak 'The tile does not contain any " |
...
" area'
|
52
|
|
|
|
|
|
|
; eval |
|
53
|
4
|
|
|
|
|
9
|
{ local $SIG{__DIE__} |
|
|
4
|
|
|
|
|
24
|
|
|
54
|
4
|
|
|
|
|
43
|
; $p = HTML::PullParser->new( doc => $Hrows |
|
55
|
|
|
|
|
|
|
, start => 'tag, text', |
|
56
|
|
|
|
|
|
|
, end => 'tag, text' |
|
57
|
|
|
|
|
|
|
) |
|
58
|
|
|
|
|
|
|
} |
|
59
|
4
|
50
|
|
|
|
549
|
; if ($@) |
|
60
|
0
|
|
|
|
|
0
|
{ croak "Problem with the HTML parser: $@" |
|
61
|
|
|
|
|
|
|
} |
|
62
|
4
|
|
|
|
|
16
|
; ( my $ri |
|
63
|
|
|
|
|
|
|
= my $di |
|
64
|
|
|
|
|
|
|
= my $td |
|
65
|
|
|
|
|
|
|
= my $in_tr |
|
66
|
|
|
|
|
|
|
= my $in_td |
|
67
|
|
|
|
|
|
|
= RESET |
|
68
|
|
|
|
|
|
|
) |
|
69
|
|
|
|
|
|
|
; my $err = sub |
|
70
|
0
|
|
|
0
|
|
0
|
{ croak "Unespected HTML tag $_[0] found in the tile" |
|
71
|
|
|
|
|
|
|
} |
|
72
|
4
|
|
|
|
|
25
|
; while ( my $tok = $p->get_token ) |
|
|
4
|
|
|
|
|
25
|
|
|
73
|
24
|
|
|
|
|
487
|
{ my ( $tag, $text ) = @$tok |
|
74
|
24
|
100
|
|
|
|
102
|
; if ( $tag eq 'tr' ) |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
5
|
50
|
33
|
|
|
32
|
{ ( not $in_tr and not $in_td ) or $err->($text) |
|
76
|
5
|
|
|
|
|
22
|
; $$rows[$ri]{Srow} = $text |
|
77
|
5
|
|
|
|
|
26
|
; $in_tr = TRUE |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif ( $tag eq '/tr') |
|
80
|
5
|
50
|
33
|
|
|
35
|
{ ( $in_tr and not $in_td) or $err->($text) |
|
81
|
5
|
|
|
|
|
16
|
; $$rows[$ri++]{Erow} = $text |
|
82
|
5
|
|
|
|
|
43
|
; $in_tr = FALSE |
|
83
|
5
|
|
|
|
|
23
|
; $di = FALSE |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
elsif ( $tag eq 'td' ) |
|
86
|
7
|
50
|
33
|
|
|
63
|
{ ($in_tr and not $in_td) or $err->($text) |
|
87
|
7
|
|
|
|
|
30
|
; $$rows[$ri]{cells}[$di]{Scell} = $text |
|
88
|
7
|
|
|
|
|
32
|
; $in_td = TRUE |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
elsif ( $tag eq '/td' ) |
|
91
|
7
|
50
|
33
|
|
|
41
|
{ ($in_tr and $in_td) or $err->($text) |
|
92
|
7
|
|
|
|
|
41
|
; $$rows[$ri]{cells}[$di++]{Ecell} .= $text |
|
93
|
7
|
|
|
|
|
13
|
; $in_td = FALSE |
|
94
|
7
|
|
|
|
|
52
|
; $td++ |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
elsif ( $tag !~ m|^/| ) |
|
97
|
0
|
0
|
0
|
|
|
0
|
{ ($in_tr and $in_td) or $err->($text) |
|
98
|
0
|
0
|
|
|
|
0
|
; $$rows[$ri]{cells}[$di]{Scell} .= $text if $in_td |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
elsif ( $tag =~ m|^/| ) |
|
101
|
0
|
0
|
0
|
|
|
0
|
{ ( $in_tr and $in_td ) or $err->($text) |
|
102
|
0
|
0
|
|
|
|
0
|
; $$rows[$ri]{cells}[$di]{Ecell} .= $text if $in_td |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
4
|
50
|
|
|
|
95
|
; $td or croak 'The tile does not contain any " | ... | " area'
|
106
|
4
|
|
|
|
|
75
|
; return { start => $start |
|
107
|
|
|
|
|
|
|
, rows => $rows |
|
108
|
|
|
|
|
|
|
, end => $end |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
; sub is_matrix |
|
113
|
4
|
|
|
4
|
1
|
10
|
{ my ($data_matrix) = shift |
|
114
|
|
|
|
|
|
|
# bi-dimensional array check |
|
115
|
4
|
|
|
|
|
10
|
; foreach my $dr ( @$data_matrix ) |
|
116
|
12
|
50
|
|
|
|
33
|
{ if ( ref $dr eq 'ARRAY' ) |
|
117
|
12
|
|
|
|
|
48
|
{ foreach my $d ( @$dr ) |
|
118
|
60
|
50
|
|
|
|
144
|
{ return 0 if ref $d |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
else |
|
122
|
0
|
|
|
|
|
0
|
{ return 0 |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
4
|
|
|
|
|
24
|
; return 1 |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
; sub tile_table |
|
129
|
4
|
|
|
4
|
1
|
35
|
{ my ( $s |
|
130
|
|
|
|
|
|
|
, $data_matrix |
|
131
|
|
|
|
|
|
|
, $tile |
|
132
|
|
|
|
|
|
|
, $mode |
|
133
|
|
|
|
|
|
|
, $checked |
|
134
|
|
|
|
|
|
|
) |
|
135
|
4
|
100
|
66
|
|
|
28
|
; if ( length(ref $_[0]) # blessed obj |
|
136
|
4
|
|
|
|
|
73
|
&& eval { $_[0]->isa(ref $_[0]) } |
|
137
|
|
|
|
|
|
|
) |
|
138
|
3
|
|
|
|
|
15
|
{ ( $s, $data_matrix, $mode, $checked) = @_ |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
else |
|
141
|
1
|
|
|
|
|
6
|
{ ( $data_matrix, $tile, $mode, $checked ) = @_ |
|
142
|
1
|
|
|
|
|
11
|
; $s = __PACKAGE__->new($tile) |
|
143
|
1
|
|
|
|
|
3
|
; undef $tile |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
4
|
|
100
|
|
|
22
|
; $mode ||= 'H_PULL V_PULL' |
|
147
|
|
|
|
|
|
|
|
|
148
|
4
|
50
|
33
|
|
|
26
|
; $checked |
|
149
|
|
|
|
|
|
|
|| is_matrix($data_matrix) |
|
150
|
|
|
|
|
|
|
|| croak 'Wrong data matrix content' |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# set Hmode and Vmode |
|
153
|
4
|
|
|
|
|
24
|
; my $m = qr/(PULL|TILE|TRIM)/ |
|
154
|
4
|
|
50
|
|
|
241
|
; my ($Hmode) = $mode =~ /\b H_ $m \b/x ; $Hmode ||= PULL |
|
|
4
|
|
|
|
|
17
|
|
|
155
|
4
|
|
50
|
|
|
147
|
; my ($Vmode) = $mode =~ /\b V_ $m \b/x ; $Vmode ||= PULL |
|
|
4
|
|
|
|
|
15
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# spread table |
|
158
|
4
|
|
|
|
|
9
|
; my $out = "\n" |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
; ROW: |
|
161
|
4
|
|
|
|
|
24
|
for ( ( my $dmi |
|
162
|
|
|
|
|
|
|
= my $tmi |
|
163
|
|
|
|
|
|
|
= RESET |
|
164
|
|
|
|
|
|
|
) |
|
165
|
|
|
|
|
|
|
; $dmi <= $#$data_matrix |
|
166
|
|
|
|
|
|
|
; ( $dmi ++ |
|
167
|
|
|
|
|
|
|
, $tmi ++ |
|
168
|
|
|
|
|
|
|
) |
|
169
|
|
|
|
|
|
|
) |
|
170
|
12
|
100
|
|
|
|
18
|
{ if ( $tmi > $#{$s->{rows}} ) |
|
|
12
|
|
|
|
|
59
|
|
|
171
|
|
|
|
|
|
|
{ |
|
172
|
7
|
100
|
|
|
|
25
|
if ( $Vmode eq PULL ) |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
173
|
3
|
|
|
|
|
6
|
{ $tmi = $#{$s->{rows}} |
|
|
3
|
|
|
|
|
5
|
|
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
elsif ( $Vmode eq TILE ) |
|
176
|
4
|
|
|
|
|
7
|
{ $tmi = RESET |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
elsif ( $Vmode eq TRIM ) |
|
179
|
|
|
|
|
|
|
{ last ROW |
|
180
|
0
|
|
|
|
|
0
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
12
|
|
|
|
|
34
|
; $out .= $s->{rows}[$tmi]{Srow} |
|
183
|
|
|
|
|
|
|
. "\n" |
|
184
|
12
|
|
|
|
|
20
|
; my $data_cells = $$data_matrix[$dmi] |
|
185
|
12
|
|
|
|
|
24
|
; my $html_cells = $$s{rows}[$tmi]{cells} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
; CELL: |
|
188
|
12
|
|
|
|
|
41
|
for ( ( my $di |
|
189
|
|
|
|
|
|
|
= my $ti |
|
190
|
|
|
|
|
|
|
= RESET |
|
191
|
|
|
|
|
|
|
) |
|
192
|
|
|
|
|
|
|
; $di <= $#$data_cells |
|
193
|
|
|
|
|
|
|
; ( $di ++ |
|
194
|
|
|
|
|
|
|
, $ti ++ |
|
195
|
|
|
|
|
|
|
) |
|
196
|
|
|
|
|
|
|
) |
|
197
|
60
|
100
|
|
|
|
118
|
{ if ( $ti > $#$html_cells ) |
|
198
|
|
|
|
|
|
|
{ |
|
199
|
36
|
100
|
|
|
|
82
|
if ( $Hmode eq PULL ) |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
200
|
24
|
|
|
|
|
34
|
{ $ti = $#$html_cells |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
elsif ( $Hmode eq TILE ) |
|
203
|
12
|
|
|
|
|
16
|
{ $ti = RESET |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
elsif ( $Hmode eq TRIM ) |
|
206
|
|
|
|
|
|
|
{ last CELL |
|
207
|
0
|
|
|
|
|
0
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
60
|
|
|
|
|
1067
|
; $out .= "\t" |
|
210
|
|
|
|
|
|
|
. $$html_cells[$ti]{Scell} |
|
211
|
|
|
|
|
|
|
. $$data_cells[$di] |
|
212
|
|
|
|
|
|
|
. $$html_cells[$ti]{Ecell} |
|
213
|
|
|
|
|
|
|
. "\n" |
|
214
|
|
|
|
|
|
|
} |
|
215
|
12
|
|
|
|
|
61
|
; $out .= $$s{rows}[$tmi]{Erow} |
|
216
|
|
|
|
|
|
|
. "\n" |
|
217
|
|
|
|
|
|
|
} |
|
218
|
4
|
|
|
|
|
50
|
; return $$s{start} |
|
219
|
|
|
|
|
|
|
. $out |
|
220
|
|
|
|
|
|
|
. $$s{end} |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
; 1 |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
__END__ |