blib/lib/HTML/TableTiler.pm

filter: Statementstmt 91.6% 99 / 108 Branchbran 55.8% 38 / 68 Conditioncond 40.6% 13 / 32 MC/DCmcdc 15.0% 3 / 20 Subroutinesub 90.9% 10 / 11 Podpod 100% 3 / 3 totaltotal 68.6% 166 / 242 CC 49 SCAR 37.3
CC
49
Cov
72%
_parse_table
81.7
tile_table
20.5
is_matrix
5.5
CRAP 41.8
↑ Summary
1 package HTML::TableTiler ;
2 4 $VERSION = 1.21 ;
3 4 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶; use Carp
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶; use HTML::PullParser 1.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶; use IO::Util 1.2
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ; require Exporter
13 4 ; @HTML::TableTiler::ISA = qw| Exporter |
14 4 ; @HTML::TableTiler::EXPORT_OK = qw| tile_table |
15  
16 ; BEGIN
17 4 ▶ { *PULL = sub () { 'PULL' }
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ; *TILE = sub () { 'TILE' }
19 4 ; *TRIM = sub () { 'TRIM' }
20 4 ; *TRUE = sub () { 1 }
21 4 ; *FALSE = sub () { 0 }
22 4 ; *RESET = sub () { 0 }
23 4 }
24  
25 ; sub new
26 4 ▶ { my $c = shift
Subroutine new: called CC=4 SCAR=13.9
Pod documented
27 4 ▶ ; my $t = shift || \ '<table><tr><td></td></tr></table>'
Condition100%2/2
shift() || \'<table><tr><td></td></tr></table>'
l!l
31
MC/DC100%1/1
shift() || \'<table><tr><td></td></tr></table>'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
28 4 ▶ ; $t = IO::Util::slurp($t)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t eq "SCALAR" 3 1 4
29 unless ref $t eq 'SCALAR'
30 4 ▶ ; $$t or croak 'The tile content is empty'
Branch: 1 branch
BranchTrueFalseTotal
$$t or croak("The tile content is empty") 4 0 4
31 4 ; my $s = _parse_table($t)
32 4 ; bless $s, $c
33 }
34  
35 ; sub _parse_table
36 4 ▶ { my ( $content ) = shift
Subroutine _parse_table: called CC=25 SCAR=44.0
37 4 ; my ( $start
38 , $Hrows
39 , $end
40 )
41 = $$content =~ m| ^
42 (.*?) # start
43 ( <TR[^>]*?> .* </TR> ) # Hrows
44 (.*) # end
45 $
46 |xsi
47 4 ; my ( $p
48 , $rows
49 , $ignore
50 )
51 4 ▶ ; $Hrows or croak 'The tile does not contain any "<tr>...</tr>" area'
Branch: 1 branch
BranchTrueFalseTotal
$Hrows or croak("The tile does not contain any \"<tr>...</tr>\" area") 4 0 4
52 ; eval
53 4 { local $SIG{__DIE__}
54 4 ; $p = HTML::PullParser->new( doc => $Hrows
55 , start => 'tag, text',
56 , end => 'tag, text'
57 )
58 }
59 4 ▶ ; if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
60 0 { croak "Problem with the HTML parser: $@"
61 }
62 4 ; ( 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 ▶ { croak "Unespected HTML tag $_[0] found in the tile"
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 }
72 4 ▶ ; while ( my $tok = $p->get_token )
Branch: 1 branch
BranchTrueFalseTotal
if (my $tok = $p->get_token) 24 4 28
73 24 { my ( $tag, $text ) = @$tok
74 24 ▶ ; if ( $tag eq 'tr' )
Branch: 6 branches
BranchTrueFalseTotal
if ($tag eq 'tr') { } 5 19 24
elsif ($tag eq '/tr') { } 5 14 19
elsif ($tag eq 'td') { } 7 7 14
elsif ($tag eq '/td') { } 7 0 7
elsif (not $tag =~ m[^/]) { } 0 0 0
elsif ($tag =~ m[^/]) { } 0 0 0
75 5 ▶ { ( not $in_tr and not $in_td ) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr || $in_td and &$err($text) 0 5 5
Condition33%1/3
$in_tr or $in_td
l!l&&r!l&&!r
005
MC/DC0%0/2
$in_tr or $in_td
$in_tr $in_td
Truth table33%1/3
A or B
A= $in_trB= $in_td
ABresult
1X1
011
000
76 5 ; $$rows[$ri]{Srow} = $text
77 5 ; $in_tr = TRUE
78 }
79 elsif ( $tag eq '/tr')
80 5 ▶ { ( $in_tr and not $in_td) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr and not $in_td or &$err($text) 5 0 5
Condition33%1/3
$in_tr and not $in_td
!ll&&!rl&&r
005
MC/DC0%0/2
$in_tr and not $in_td
$in_tr not $in_td
Truth table33%1/3
A and not(B)
A= $in_trB= not $in_td
ABresult
0X0
100
111
81 5 ; $$rows[$ri++]{Erow} = $text
82 5 ; $in_tr = FALSE
83 5 ; $di = FALSE
84 }
85 elsif ( $tag eq 'td' )
86 7 ▶ { ($in_tr and not $in_td) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr and not $in_td or &$err($text) 7 0 7
Condition33%1/3
$in_tr and not $in_td
!ll&&!rl&&r
007
MC/DC0%0/2
$in_tr and not $in_td
$in_tr not $in_td
Truth table33%1/3
A and not(B)
A= $in_trB= not $in_td
ABresult
0X0
100
111
87 7 ; $$rows[$ri]{cells}[$di]{Scell} = $text
88 7 ; $in_td = TRUE
89 }
90 elsif ( $tag eq '/td' )
91 7 ▶ { ($in_tr and $in_td) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr and $in_td or &$err($text) 7 0 7
Condition33%1/3
$in_tr and $in_td
!ll&&!rl&&r
007
MC/DC0%0/2
$in_tr and $in_td
$in_tr $in_td
Truth table33%1/3
A and B
A= $in_trB= $in_td
ABresult
0X0
100
111
92 7 ; $$rows[$ri]{cells}[$di++]{Ecell} .= $text
93 7 ; $in_td = FALSE
94 7 ; $td++
95 }
96 elsif ( $tag !~ m|^/| )
97 0 ▶ { ($in_tr and $in_td) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr and $in_td or &$err($text) 0 0 0
Condition0%0/3
$in_tr and $in_td
!ll&&!rl&&r
000
MC/DC0%0/2
$in_tr and $in_td
$in_tr $in_td
Truth table0%0/3
A and B
A= $in_trB= $in_td
ABresult
0X0
100
111
98 0 ▶ ; $$rows[$ri]{cells}[$di]{Scell} .= $text if $in_td
Branch: 1 branch
BranchTrueFalseTotal
if $in_td 0 0 0
99 }
100 elsif ( $tag =~ m|^/| )
101 0 ▶ { ( $in_tr and $in_td ) or $err->($text)
Branch: 1 branch
BranchTrueFalseTotal
$in_tr and $in_td or &$err($text) 0 0 0
Condition0%0/3
$in_tr and $in_td
!ll&&!rl&&r
000
MC/DC0%0/2
$in_tr and $in_td
$in_tr $in_td
Truth table0%0/3
A and B
A= $in_trB= $in_td
ABresult
0X0
100
111
102 0 ▶ ; $$rows[$ri]{cells}[$di]{Ecell} .= $text if $in_td
Branch: 1 branch
BranchTrueFalseTotal
if $in_td 0 0 0
103 }
104 }
105 4 ▶ ; $td or croak 'The tile does not contain any "<td>...</td>" area'
Branch: 1 branch
BranchTrueFalseTotal
$td or croak("The tile does not contain any \"<td>...</td>\" area") 4 0 4
106 4 ; return { start => $start
107 , rows => $rows
108 , end => $end
109 }
110 }
111  
112 ; sub is_matrix
113 4 ▶ { my ($data_matrix) = shift
Subroutine is_matrix: called CC=5 SCAR=17.1
Pod documented
114 # bi-dimensional array check
115 4 ; foreach my $dr ( @$data_matrix )
116 12 ▶ { if ( ref $dr eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dr eq 'ARRAY') { } 12 0 12
117 12 { foreach my $d ( @$dr )
118 60 ▶ { return 0 if ref $d
Branch: 1 branch
BranchTrueFalseTotal
if ref $d 0 60 60
119 }
120 }
121 else
122 0 { return 0
123 }
124 }
125 4 ; return 1
126 }
127
128 ; sub tile_table
129 4 ▶ { my ( $s
Subroutine tile_table: called CC=18 SCAR=30.2
Pod documented
130 , $data_matrix
131 , $tile
132 , $mode
133 , $checked
134 )
135 4 ▶ ; if ( length(ref $_[0]) # blessed obj
Branch: 1 branch
BranchTrueFalseTotal
if (length ref $_[0] and eval { do { $_[0]->isa(ref $_[0]) } }) { } 3 1 4
Condition66%2/3
length ref $_[0] and eval { do { $_[0]->isa(ref $_[0]) } }
!ll&&!rl&&r
013
MC/DC50%1/2
length ref $_[0] and eval { do { $_[0]->isa(ref $_[0]) } }
length ref $_[0] eval { do { $_[0]->isa(ref $_[0]) } }
Truth table66%2/3
A and B
A= length ref $_[0]B= eval { do { $_[0]->isa(ref $_[0]) } }
ABresult
0X0
100
111
136 4 && eval { $_[0]->isa(ref $_[0]) }
137 )
138 3 { ( $s, $data_matrix, $mode, $checked) = @_
139 }
140 else
141 1 { ( $data_matrix, $tile, $mode, $checked ) = @_
142 1 ; $s = __PACKAGE__->new($tile)
143 1 ; undef $tile
144 }
145
146 4 ▶ ; $mode ||= 'H_PULL V_PULL'
Condition100%2/2
$mode ||= "H_PULL V_PULL"
l!l
22
MC/DC100%1/1
$mode ||= "H_PULL V_PULL"
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
147  
148 4 ▶ ; $checked
Branch: 1 branch
BranchTrueFalseTotal
$checked or is_matrix($data_matrix) or croak("Wrong data matrix content") 4 0 4
Condition33%1/3
$checked or is_matrix($data_matrix)
l!l&&r!l&&!r
040
MC/DC0%0/2
$checked or is_matrix($data_matrix)
$checked is_matrix($data_matrix)
Truth table33%1/3
A or B
A= $checkedB= is_matrix($data_matrix)
ABresult
1X1
011
000
149 || is_matrix($data_matrix)
150 || croak 'Wrong data matrix content'
151
152 # set Hmode and Vmode
153 4 ; my $m = qr/(PULL|TILE|TRIM)/
154 4 ▶ ; my ($Hmode) = $mode =~ /\b H_ $m \b/x ; $Hmode ||= PULL
Condition50%1/2
$Hmode ||= "PULL"
l!l
40
MC/DC0%0/1
$Hmode ||= "PULL"
$Hmode
Truth table50%1/2
A
A= $Hmode
Aresult
11
00
155 4 ▶ ; my ($Vmode) = $mode =~ /\b V_ $m \b/x ; $Vmode ||= PULL
Condition50%1/2
$Vmode ||= "PULL"
l!l
40
MC/DC0%0/1
$Vmode ||= "PULL"
$Vmode
Truth table50%1/2
A
A= $Vmode
Aresult
11
00
156  
157 # spread table
158 4 ; my $out = "\n"
159
160 ; ROW:
161 4 ▶ for ( ( my $dmi
Branch: 1 branch
BranchTrueFalseTotal
if ($dmi <= $data_matrix->$#*) 12 4 16
162 = my $tmi
163 = RESET
164 )
165 ; $dmi <= $#$data_matrix
166 ; ( $dmi ++
167 , $tmi ++
168 )
169 )
170 12 ▶ { if ( $tmi > $#{$s->{rows}} )
Branch: 1 branch
BranchTrueFalseTotal
if ($tmi > $#{$$s{"rows"};}) 7 5 12
171 {
172 7 ▶ if ( $Vmode eq PULL )
Branch: 3 branches
BranchTrueFalseTotal
if ($Vmode eq 'PULL') { } 3 4 7
elsif ($Vmode eq 'TILE') { } 4 0 4
elsif ($Vmode eq 'TRIM') { } 0 0 0
173 3 { $tmi = $#{$s->{rows}}
174 }
175 elsif ( $Vmode eq TILE )
176 4 { $tmi = RESET
177 }
178 elsif ( $Vmode eq TRIM )
179 { last ROW
180 0 }
181 }
182 ; $out .= $s->{rows}[$tmi]{Srow}
183 12 . "\n"
184 12 ; my $data_cells = $$data_matrix[$dmi]
185 ; my $html_cells = $$s{rows}[$tmi]{cells}
186
187 12 ; CELL:
188 12 ▶ for ( ( my $di
Branch: 1 branch
BranchTrueFalseTotal
if ($di <= $data_cells->$#*) 60 12 72
189 = my $ti
190 = RESET
191 )
192 ; $di <= $#$data_cells
193 ; ( $di ++
194 , $ti ++
195 )
196 )
197 60 ▶ { if ( $ti > $#$html_cells )
Branch: 1 branch
BranchTrueFalseTotal
if ($ti > $html_cells->$#*) 36 24 60
198 {
199 36 ▶ if ( $Hmode eq PULL )
Branch: 3 branches
BranchTrueFalseTotal
if ($Hmode eq 'PULL') { } 24 12 36
elsif ($Hmode eq 'TILE') { } 12 0 12
elsif ($Hmode eq 'TRIM') { } 0 0 0
200 24 { $ti = $#$html_cells
201 }
202 elsif ( $Hmode eq TILE )
203 12 { $ti = RESET
204 }
205 elsif ( $Hmode eq TRIM )
206 { last CELL
207 0 }
208 }
209 ; $out .= "\t"
210 . $$html_cells[$ti]{Scell}
211 . $$data_cells[$di]
212 . $$html_cells[$ti]{Ecell}
213 60 . "\n"
214 }
215 ; $out .= $$s{rows}[$tmi]{Erow}
216 12 . "\n"
217 }
218 ; return $$s{start}
219 . $out
220 . $$s{end}
221 4 }
222  
223 4 ; 1
224  
225 __END__
↑ Summary