blib/lib/Spreadsheet/Read.pm

filter: Statementstmt 73.0% 652 / 892 Branchbran 67.3% 529 / 786 Conditioncond 55.4% 228 / 411 MC/DCmcdc 40.0% 90 / 225 Subroutinesub 93.5% 58 / 62 Podpod 100% 15 / 15 totaltotal 65.7% 1572 / 2391 CC 581 SCAR 87.7
CC
581
Cov
67%
ReadData
12168.0
_clipsheets
50.1
add
27.1
CRAP 6414.1
↑ Summary
1 #!/usr/bin/perl
2  
3 package Spreadsheet::Read;
4  
5 =head1 NAME
6  
7 Spreadsheet::Read - Read the data from a spreadsheet
8  
9 =head1 SYNOPSIS
10  
11 use Spreadsheet::Read;
12 my $book = ReadData ("test.csv", sep => ";");
13 my $book = ReadData ("test.sxc");
14 my $book = ReadData ("test.ods");
15 my $book = ReadData ("test.xls");
16 my $book = ReadData ("test.xlsx");
17 my $book = ReadData ("test.xlsm");
18 my $book = ReadData ("test.gnumeric");
19 my $book = ReadData ($fh, parser => "xls");
20  
21 Spreadsheet::Read::add ($book, "sheet.csv");
22  
23 my $sheet = $book->[1]; # first datasheet
24 my $cell = $book->[1]{A3}; # content of field A3 of sheet 1
25 my $cell = $book->[1]{cell}[1][3]; # same, unformatted
26  
27 # OO API
28 my $book = Spreadsheet::Read->new ("file.csv");
29 my $sheet = $book->sheet (1);
30 my $cell = $sheet->cell ("A3");
31 my $cell = $sheet->cell (1, 3);
32  
33 $book->add ("test.xls");
34  
35 =cut
36  
37 70 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 70 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 70 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 70 our $VERSION = "0.95";
42 1 ▶sub Version { $VERSION }
Subroutine Version: called CC=1 SCAR=0.0
Pod documented
43  
44 70 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 70 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 70 our @ISA = qw( Exporter );
47 70 our @EXPORT = qw( ReadData cell2cr cr2cell );
48 70 our @EXPORT_OK = qw( parses rows cellrow row add );
49  
50 70 ▶use Encode qw( decode );
Subroutine BEGIN: called CC=1 SCAR=0.0
51 70 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
52 70 ▶use File::Temp qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
53 70 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 70 my @parsers = (
56 [ csv => "Text::CSV_XS", "0.71" ],
57 [ csv => "Text::CSV_PP", "1.17" ],
58 [ csv => "Text::CSV", "1.17" ],
59 [ ods => "Spreadsheet::ParseODS", "0.26" ],
60 [ ods => "Spreadsheet::ReadSXC", "0.26" ],
61 [ sxc => "Spreadsheet::ParseODS", "0.26" ],
62 [ sxc => "Spreadsheet::ReadSXC", "0.26" ],
63 [ sxc => "Spreadsheet::ReadSXC__BAD", "0.26" ], # For testing
64 [ xls => "Spreadsheet::ParseExcel", "0.34" ],
65 [ xlsx => "Spreadsheet::ParseXLSX", "0.24" ],
66 [ xlsm => "Spreadsheet::ParseXLSX", "0.24" ],
67 [ xlsx => "Spreadsheet::XLSX", "0.13" ],
68 [ xlsx => "Excel::ValueReader::XLSX", "1.13" ],
69 # [ prl => "Spreadsheet::Perl", "" ],
70 [ sc => "Spreadsheet::Read", "0.01" ],
71 [ gnumeric => "Spreadsheet::ReadGnumeric", "0.2" ],
72  
73 [ zzz1 => "Z10::Just::For::Testing", "1.23" ],
74 [ zzz2 => "Z20::Just::For::Testing", "" ],
75 [ zzz3 => "Z30::Just::For::Testing", "1.00" ],
76  
77 # Helper modules
78 [ ios => "IO::Scalar", "" ],
79 [ dmp => "Data::Peek", "" ],
80 );
81 70 my %can = ( supports => { map { $_->[1] => $_->[2] } @parsers });
82 70 foreach my $p (@parsers) {
83 1400 my $format = $p->[0];
84 1400 ▶ $can{$format} and next;
Branch: 1 branch
BranchTrueFalseTotal
$can{$format} and next 72 1328 1400
85 1328 $can{$format} = "";
86 1328 ▶ my $preset = $ENV{"SPREADSHEET_READ_\U$format"} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $preset = $ENV{"SPREADSHEET_READ_\U$format\E"} or next 40 1288 1328
87 40 my $min_version = $can{supports}{$preset};
88 40 ▶ unless ($min_version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($min_version) 1 39 40
89 # Catch weirdness like $SPREADSHEET_READ_XLSX = "DBD::Oracle"
90 1 $can{$format} = "!$preset is not supported for the $format format";
91 1 next;
92 }
93 39 ▶ if (eval "local \$_; require $preset" and not $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "local \$_; require $preset" and not $@) { } 16 23 39
Condition66%2/3
eval "local \$_; require $preset" and not $@
!ll&&!rl&&r
23016
MC/DC50%1/2
eval "local \$_; require $preset" and not $@
eval "local \$_; require $preset" not $@
Truth table66%2/3
A and not(B)
A= eval "local \$_; require $preset"B= not $@
ABresult
0X0
100
111
94 # forcing a parser should still check the version
95 16 my $ok;
96 16 my $has = $preset->VERSION;
97 16 $has =~ s/_[0-9]+$//; # Remove beta-part
98 16 ▶ if ($min_version =~ m/^v([0-9.]+)/) { # clumsy versions
Branch: 1 branch
BranchTrueFalseTotal
if ($min_version =~ /^v([0-9.]+)/) { } 0 16 16
99 0 my @min = split m/\./ => $1;
100 0 $has =~ s/^v//;
101 0 my @has = split m/\./ => $has;
102 0 $ok = (($has[0] * 1000 + $has[1]) * 1000 + $has[2]) >=
103 (($min[0] * 1000 + $min[1]) * 1000 + $min[2]);
104 }
105 else { # normal versions
106 16 $ok = $has >= $min_version;
107 }
108 16 ▶ $ok or $preset = "!$preset";
Branch: 1 branch
BranchTrueFalseTotal
$ok or $preset = "!$preset" 16 0 16
109 }
110 else {
111 23 $preset = "!$preset";
112 }
113 39 $can{$format} = $preset;
114 }
115 70 delete $can{supports};
116 70 foreach my $p (@parsers) {
117 1400 my ($flag, $mod, $vsn) = @$p;
118 1400 ▶ $can{$flag} and next;
Branch: 1 branch
BranchTrueFalseTotal
$can{$flag} and next 281 1119 1400
119 1119 ▶ eval "require $mod; \$vsn and ${mod}->VERSION (\$vsn); \$can{\$flag} = '$mod'" and next;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $mod; \$vsn and $mod->VERSION (\$vsn); \$can{\$flag} = '${mod}'" and next 459 660 1119
120 660 $p->[0] = "! Cannot use $mod version $vsn: $@";
121 660 ▶ $can{$flag} = $@ =~ m/need to install|can(?:not|'t) locate/i
Branch: 1 branch
BranchTrueFalseTotal
$@ =~ /need to install|can(?:not|'t) locate/i ? : 263 397 660
122 ? 0 # Not found
123 : ""; # Too old
124 }
125 70 $can{sc} = __PACKAGE__; # SquirrelCalc is built-in
126  
127 # Define ->get_active_sheet if not defined (yet)
128 76 ▶sub _def_gas {
Subroutine _def_gas: called CC=6 SCAR=28.1
129 76 for ([ 0.61, $Spreadsheet::ParseExcel::VERSION, *Spreadsheet::ParseExcel::Workbook::get_active_sheet ],
130 [ 0.25, $Spreadsheet::ParseODS::VERSION, *Spreadsheet::ParseODS::Workbook::get_active_sheet ],
131 [ 9.99, $Excel::ValueReader::XLSX::VERSION, *Excel::ValueReader::XLSX::get_active_sheet ],
132 ) {
133 228 my ($mv, $v, $cb) = @$_;
134 228 ▶ defined $v && $v < $mv or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $v and $v < $mv or next 0 228 228
Condition66%2/3
defined $v and $v < $mv
!ll&&!rl&&r
152760
MC/DC0%0/2
defined $v and $v < $mv
defined $v $v < $mv
Truth table66%2/3
A and B
A= defined $vB= $v < $mv
ABresult
0X0
100
111
135 0 ▶ defined $cb && defined *{$cb}{CODE} and next;
Branch: 1 branch
BranchTrueFalseTotal
defined $cb and defined *{$cb;}{"CODE"} and next 0 0 0
Condition0%0/3
defined $cb and defined *{$cb;}{"CODE"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cb and defined *{$cb;}{"CODE"}
defined $cb defined *{$cb;}{"CODE"}
Truth table0%0/3
A and B
A= defined $cbB= defined *{$cb;}{"CODE"}
ABresult
0X0
100
111
136 0 ▶ *{$cb} = sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 }
138 } # _def_gas
139  
140 70 my $debug = 0;
141 70 my %def_opts = (
142 rc => 1,
143 cells => 1,
144 attr => 0,
145 clip => undef, # $opt{cells};
146 strip => 0,
147 pivot => 0,
148 dtfmt => "yyyy-mm-dd", # Format 14
149 debug => 0,
150 passwd => undef,
151 parser => undef,
152 sep => undef,
153 quote => undef,
154 label => undef,
155 merge => 0,
156 );
157 70 my @def_attr = (
158 type => "text",
159 fgcolor => undef,
160 bgcolor => undef,
161 font => undef,
162 size => undef,
163 format => undef,
164 halign => "left",
165 valign => "top",
166 bold => 0,
167 italic => 0,
168 uline => 0,
169 wrap => 0,
170 merged => 0,
171 hidden => 0,
172 locked => 0,
173 enc => "utf-8", # $ENV{LC_ALL} // $ENV{LANG} // ...
174 formula => undef,
175 );
176  
177 # Helper functions
178  
179 7 ▶sub _dump {
Subroutine _dump: called CC=2 SCAR=7.2
180 7 my ($label, $ref) = @_;
181 7 ▶ if ($can{dmp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can{'dmp'}) { } 7 0 7
182 7 print STDERR Data::Peek::DDumper ({ $label => $ref });
183 }
184 else {
185 0 print STDERR Data::Dumper->Dump ([$ref], [$label]);
186 }
187 7 my @c = caller (1);
188 7 print STDERR "<<- $c[1]:$c[2]|$c[3]\n";
189 } # _dump
190  
191 613 ▶sub _parser {
Subroutine _parser: called CC=16 SCAR=28.0
192 613 ▶ my $type = shift or return "";
Branch: 1 branch
BranchTrueFalseTotal
my $type = shift() or return "" 356 257 613
193 356 ▶ if ($type =~ m/::/ and my @p = grep { $_->[1] eq $type } @parsers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /::/ and my(@p) = grep({$_->[1] eq $type;} @parsers)) 80 276 356
Condition100%3/3
$type =~ /::/ and my(@p) = grep({$_->[1] eq $type;} @parsers)
!ll&&!rl&&r
272480
MC/DC100%2/2
$type =~ /::/ and my(@p) = grep({$_->[1] eq $type;} @parsers)
$type =~ /::/ my(@p) = grep({$_->[1] eq $type;} @parsers)
Truth table100%3/3
A and B
A= $type =~ /::/B= my(@p) = grep({$_->[1] eq $type;} @parsers)
ABresult
0X0
100
111
194 80 my $format = $p[0][0];
195 80 $ENV{"SPREADSHEET_READ_\U$format"} = $type;
196 80 eval "local \$_; require $type";
197 80 ▶ $@ and croak ("Forced backend $type for $format fails to load:\n$@");
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("Forced backend $type for $format fails to load:\n$@") 0 80 80
198 80 $can{$format} = $type;
199 80 $type = $format;
200 }
201 356 $type = lc $type;
202 356 ▶ my $ods = $can{ods} ? "ods" : "sxc";
Branch: 1 branch
BranchTrueFalseTotal
$can{'ods'} ? : 8 348 356
203 # Aliases and fullnames
204 356 ▶ $type eq "excel" and return "xls";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "excel" and return "xls" 1 355 356
205 355 ▶ $type eq "excel2007" and return "xlsx";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "excel2007" and return "xlsx" 0 355 355
206 355 ▶ $type eq "xlsm" and return "xlsx";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "xlsm" and return "xlsx" 0 355 355
207 355 ▶ $type eq "oo" and return $ods;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "oo" and return $ods 1 354 355
208 # $type eq "sxc" and return $ods;
209 354 ▶ $type eq "openoffice" and return $ods;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "openoffice" and return $ods 1 353 354
210 353 ▶ $type eq "libreoffice" and return $ods;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "libreoffice" and return $ods 0 353 353
211 353 ▶ $type eq "perl" and return "prl";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "perl" and return "prl" 0 353 353
212 353 ▶ $type eq "scalc" and return "sc";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "scalc" and return "sc" 1 352 353
213 352 ▶ $type eq "squirrelcalc" and return "sc";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "squirrelcalc" and return "sc" 0 352 352
214 352 ▶ return exists $can{$type} ? $type : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $can{$type} ? : 347 5 352
215 } # _parser
216  
217 13 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
218 13 my $class = shift;
219 13 my $r = ReadData (@_);
220 13 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 2 11 13
221 2 ▶ @_ and return; # new with arguments failed to open resource
Branch: 1 branch
BranchTrueFalseTotal
@_ and return 2 0 2
222 0 $r = [{
223 parsers => [],
224 error => undef,
225 sheets => 0,
226 sheet => { },
227 }];
228 }
229 11 bless $r => $class;
230 } # new
231  
232 1 ▶sub parsers {
Subroutine parsers: called CC=6 SCAR=18.0
Pod documented
233 1 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 0 1 1
234 1 my @c;
235 1 ▶ for (sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] }
Condition66%2/3
$Spreadsheet::Read::a->[0] cmp $Spreadsheet::Read::b->[0] || $Spreadsheet::Read::a->[1] cmp $Spreadsheet::Read::b->[1]
l!l&&r!l&&!r
3330
MC/DC0%0/2
$Spreadsheet::Read::a->[0] cmp $Spreadsheet::Read::b->[0] || $Spreadsheet::Read::a->[1] cmp $Spreadsheet::Read::b->[1]
$Spreadsheet::Read::a->[0] cmp $Spreadsheet::Read::b->[0] $Spreadsheet::Read::a->[1] cmp $Spreadsheet::Read::b->[1]
Truth table66%2/3
A || B
A= $Spreadsheet::Read::a->[0] cmp $Spreadsheet::Read::b->[0]B= $Spreadsheet::Read::a->[1] cmp $Spreadsheet::Read::b->[1]
ABresult
1X1
011
000
236 20 grep { $_->[0] !~ m{^(?:dmp|ios|!.*)$} }
237 @parsers) {
238 14 my ($typ, $mod, $min) = @$_;
239 14 eval "local \$_; require $mod";
240 14 ▶ my $vsn = $@ ? "-" : eval { $mod->VERSION };
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 7 7 14
241 push @c => {
242 ext => $typ,
243 mod => $mod,
244 min => $min,
245 vsn => $vsn,
246 14 ▶ def => $can{$typ} eq $mod ? "*" : "",
Branch: 1 branch
BranchTrueFalseTotal
$can{$typ} eq $mod ? : 5 9 14
247 };
248 }
249 1 @c;
250 } # parsers
251  
252 # Spreadsheet::Read::parses ("csv") or die "Cannot parse CSV"
253 83 ▶sub parses {
Subroutine parses: called CC=7 SCAR=19.5
Pod documented
254 83 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 1 82 83
255  
256 my $type = shift or
257 83 ▶ return sort grep { !m/^(?:dmp|ios)/ && $can{$_} !~ m{^!} }
Branch: 1 branch
BranchTrueFalseTotal
my $type = shift() or return sort(grep({not /^(?:dmp|ios)/ || $can{$_} =~ /^!/;} keys %can)) 82 1 83
Condition66%2/3
/^(?:dmp|ios)/ || $can{$_} =~ /^!/
l!l&&r!l&&!r
2011
MC/DC50%1/2
/^(?:dmp|ios)/ || $can{$_} =~ /^!/
/^(?:dmp|ios)/ $can{$_} =~ /^!/
Truth table66%2/3
A || B
A= /^(?:dmp|ios)/B= $can{$_} =~ /^!/
ABresult
1X1
011
000
258 keys %can;
259  
260 82 ▶ $type = _parser ($type) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$type = _parser($type) or return 0 81 1 82
261 81 ▶ if ($can{$type} =~ m/^!\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can{$type} =~ /^!\s*(.*)/) 24 57 81
262 24 $@ = $1;
263 24 return 0;
264 }
265 57 ▶ return $can{$type} || 0;
Condition100%2/2
$can{$type} || 0
l!l
4611
MC/DC100%1/1
$can{$type} || 0
$can{$type}
Truth table100%2/2
A
A= $can{$type}
Aresult
11
00
266 } # parses
267  
268 4 ▶sub sheets {
Subroutine sheets: called CC=3 SCAR=11.0
Pod documented
269 4 my $ctrl = shift->[0];
270 4 ▶ wantarray or return $ctrl->{sheets};
Branch: 1 branch
BranchTrueFalseTotal
wantarray or return $ctrl->{"sheets"} 2 2 4
271  
272 2 ▶ my $s = $ctrl->{sheet} or return (); # No labels defined
Branch: 1 branch
BranchTrueFalseTotal
my $s = $ctrl->{"sheet"} or return () 2 0 2
273 2 sort { $s->{$a} <=> $s->{$b} } keys %$s;
274 } # sheets
275  
276 # col2label (4) => "D"
277 28351 ▶sub col2label {
Subroutine col2label: called CC=5 SCAR=16.1
Pod documented
278 28351 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 1 28350 28351
279 28351 my $c = shift;
280 28351 ▶ defined $c && $c > 0 or return "";
Branch: 1 branch
BranchTrueFalseTotal
defined $c and $c > 0 or return "" 28347 4 28351
Condition100%3/3
defined $c and $c > 0
!ll&&!rl&&r
1328347
MC/DC100%2/2
defined $c and $c > 0
defined $c $c > 0
Truth table100%3/3
A and B
A= defined $cB= $c > 0
ABresult
0X0
100
111
281 28347 my $cell = "";
282 28347 ▶ while ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 28364 28347 56711
283 70 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
284  
285 28364 substr $cell, 0, 0, chr (--$c % 26 + ord "A");
286 28364 $c /= 26;
287 }
288 28347 $cell;
289 } # col2label
290  
291 # label2col ("D") => 4
292 657 ▶sub label2col {
Subroutine label2col: called CC=6 SCAR=17.9
Pod documented
293 657 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 1 656 657
294 657 ▶ my $l = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $l = shift() or return 655 2 657
295 655 ▶ $l =~ m/^[0-9]+$/ and return $l + 0;
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /^[0-9]+$/ and return $l + 0 0 655 655
296 655 ▶ $l =~ m/^[A-Za-z]+$/ or return;
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /^[A-Za-z]+$/ or return 653 2 655
297 653 $l = uc $l;
298 653 my $c = 0;
299 653 ▶ while ($l =~ s/^([A-Z])//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ s/^([A-Z])//) 670 653 1323
300 670 $c = 26 * $c + 1 + ord ($1) - ord ("A");
301 }
302 653 return $c;
303 } # label2col
304  
305 # cr2cell (4, 18) => "D18"
306 # No prototype to allow 'cr2cell (@rowcol)'
307 27987 ▶sub cr2cell {
Subroutine cr2cell: called CC=6 SCAR=17.9
Pod documented
308 27987 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 1 27986 27987
309 27987 my ($c, $r) = @_;
310 27987 ▶ defined $c && defined $r && $c > 0 && $r > 0 or return "";
Branch: 1 branch
BranchTrueFalseTotal
defined $c and defined $r and $c > 0 and $r > 0 or return "" 27981 6 27987
Condition100%9/9
defined $c and defined $r and $c > 0 and $r > 0
!ll&&!rl&&r
5127981
defined $c and defined $r and $c > 0
!ll&&!rl&&r
2327982
defined $c and defined $r
!ll&&!rl&&r
1127985
MC/DC100%4/4
defined $c and defined $r and $c > 0 and $r > 0
defined $c defined $r $c > 0 $r > 0
Truth table100%5/5
A and B and C and D
A= defined $cB= defined $rC= $c > 0D= $r > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
311 27981 col2label ($c) . $r;
312 } # cr2cell
313  
314 # cell2cr ("D18") => (4, 18)
315 644 ▶sub cell2cr {
Subroutine cell2cr: called CC=4 SCAR=13.9
Pod documented
316 644 ▶ ref $_[0] eq __PACKAGE__ and shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ and shift() 16 628 644
317 644 ▶ my ($cc, $r) = (uc ($_[0]||"") =~ m/^([A-Z-z]+)([0-9]+)$/) or return (0, 0);
Branch: 1 branch
BranchTrueFalseTotal
() = uc($_[0] or "") =~ /^([A-Z-z]+)([0-9]+)$/ or return 0, 0 640 4 644
Condition100%2/2
$_[0] || ''
l!l
6422
MC/DC100%1/1
$_[0] || ''
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
318 640 (label2col ($cc), $r);
319 } # cell2cr
320  
321 # my @row = cellrow ($book->[1], 1);
322 # my @row = $book->cellrow (1, 1);
323 10 ▶sub cellrow {
Subroutine cellrow: called CC=10 SCAR=23.3
Pod documented
324 10 ▶ my $sheet = ref $_[0] eq __PACKAGE__ ? (shift)->[shift] : shift or return;
Branch: 2 branches
BranchTrueFalseTotal
my $sheet = ref $_[0] eq __PACKAGE__ ? (shift())->[shift()] : shift() or return 9 1 10
ref $_[0] eq __PACKAGE__ ? : 7 3 10
325 9 ▶ ref $sheet eq "HASH" && exists $sheet->{cell} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $sheet eq "HASH" and exists $sheet->{"cell"} or return 7 2 9
Condition66%2/3
ref $sheet eq "HASH" and exists $sheet->{"cell"}
!ll&&!rl&&r
027
MC/DC50%1/2
ref $sheet eq "HASH" and exists $sheet->{"cell"}
ref $sheet eq "HASH" exists $sheet->{"cell"}
Truth table66%2/3
A and B
A= ref $sheet eq "HASH"B= exists $sheet->{"cell"}
ABresult
0X0
100
111
326 7 ▶ exists $sheet->{maxcol} && exists $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"} or return 7 0 7
Condition33%1/3
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
!ll&&!rl&&r
007
MC/DC0%0/2
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
exists $sheet->{"maxcol"} exists $sheet->{"maxrow"}
Truth table33%1/3
A and B
A= exists $sheet->{"maxcol"}B= exists $sheet->{"maxrow"}
ABresult
0X0
100
111
327 7 ▶ my $row = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $row = shift() or return 6 1 7
328 6 ▶ $row > 0 && $row <= $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
$row > 0 and $row <= $sheet->{"maxrow"} or return 4 2 6
Condition100%3/3
$row > 0 and $row <= $sheet->{"maxrow"}
!ll&&!rl&&r
114
MC/DC100%2/2
$row > 0 and $row <= $sheet->{"maxrow"}
$row > 0 $row <= $sheet->{"maxrow"}
Truth table100%3/3
A and B
A= $row > 0B= $row <= $sheet->{"maxrow"}
ABresult
0X0
100
111
329 4 my $s = $sheet->{cell};
330 4 map { $s->[$_][$row] } 1..$sheet->{maxcol};
331 } # cellrow
332  
333 # my @row = row ($book->[1], 1);
334 # my @row = $book->row (1, 1);
335 10 ▶sub row {
Subroutine row: called CC=10 SCAR=23.3
Pod documented
336 10 ▶ my $sheet = ref $_[0] eq __PACKAGE__ ? (shift)->[shift] : shift or return;
Branch: 2 branches
BranchTrueFalseTotal
my $sheet = ref $_[0] eq __PACKAGE__ ? (shift())->[shift()] : shift() or return 9 1 10
ref $_[0] eq __PACKAGE__ ? : 7 3 10
337 9 ▶ ref $sheet eq "HASH" && exists $sheet->{cell} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $sheet eq "HASH" and exists $sheet->{"cell"} or return 7 2 9
Condition66%2/3
ref $sheet eq "HASH" and exists $sheet->{"cell"}
!ll&&!rl&&r
027
MC/DC50%1/2
ref $sheet eq "HASH" and exists $sheet->{"cell"}
ref $sheet eq "HASH" exists $sheet->{"cell"}
Truth table66%2/3
A and B
A= ref $sheet eq "HASH"B= exists $sheet->{"cell"}
ABresult
0X0
100
111
338 7 ▶ exists $sheet->{maxcol} && exists $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"} or return 7 0 7
Condition33%1/3
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
!ll&&!rl&&r
007
MC/DC0%0/2
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
exists $sheet->{"maxcol"} exists $sheet->{"maxrow"}
Truth table33%1/3
A and B
A= exists $sheet->{"maxcol"}B= exists $sheet->{"maxrow"}
ABresult
0X0
100
111
339 7 ▶ my $row = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $row = shift() or return 6 1 7
340 6 ▶ $row > 0 && $row <= $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
$row > 0 and $row <= $sheet->{"maxrow"} or return 4 2 6
Condition100%3/3
$row > 0 and $row <= $sheet->{"maxrow"}
!ll&&!rl&&r
114
MC/DC100%2/2
$row > 0 and $row <= $sheet->{"maxrow"}
$row > 0 $row <= $sheet->{"maxrow"}
Truth table100%3/3
A and B
A= $row > 0B= $row <= $sheet->{"maxrow"}
ABresult
0X0
100
111
341 4 map { $sheet->{cr2cell ($_, $row)} } 1..$sheet->{maxcol};
342 } # row
343  
344 # Convert {cell}'s [column][row] to a [row][column] list
345 # my @rows = rows ($book->[1]);
346 33 ▶sub rows {
Subroutine rows: called CC=7 SCAR=19.5
Pod documented
347 33 ▶ my $sheet = ref $_[0] eq __PACKAGE__ ? (shift)->[shift] : shift or return;
Branch: 2 branches
BranchTrueFalseTotal
my $sheet = ref $_[0] eq __PACKAGE__ ? (shift())->[shift()] : shift() or return 30 3 33
ref $_[0] eq __PACKAGE__ ? : 0 33 33
348 30 ▶ ref $sheet eq "HASH" && exists $sheet->{cell} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $sheet eq "HASH" and exists $sheet->{"cell"} or return 26 4 30
Condition100%3/3
ref $sheet eq "HASH" and exists $sheet->{"cell"}
!ll&&!rl&&r
3126
MC/DC100%2/2
ref $sheet eq "HASH" and exists $sheet->{"cell"}
ref $sheet eq "HASH" exists $sheet->{"cell"}
Truth table100%3/3
A and B
A= ref $sheet eq "HASH"B= exists $sheet->{"cell"}
ABresult
0X0
100
111
349 26 ▶ exists $sheet->{maxcol} && exists $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"} or return 5 21 26
Condition100%3/3
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
!ll&&!rl&&r
1475
MC/DC100%2/2
exists $sheet->{"maxcol"} and exists $sheet->{"maxrow"}
exists $sheet->{"maxcol"} exists $sheet->{"maxrow"}
Truth table100%3/3
A and B
A= exists $sheet->{"maxcol"}B= exists $sheet->{"maxrow"}
ABresult
0X0
100
111
350 5 my $s = $sheet->{cell};
351  
352 map {
353 20 my $r = $_;
354 20 [ map { $s->[$_][$r] } 1..$sheet->{maxcol} ];
355 5 } 1..$sheet->{maxrow};
356 } # rows
357  
358 37 ▶sub sheet {
Subroutine sheet: called CC=9 SCAR=22.0
Pod documented
359 37 my ($book, $sheet) = @_;
360 37 ▶ $book && $sheet or return;
Branch: 1 branch
BranchTrueFalseTotal
$book and $sheet or return 35 2 37
Condition100%3/3
$book and $sheet
!ll&&!rl&&r
1135
MC/DC100%2/2
$book and $sheet
$book $sheet
Truth table100%3/3
A and B
A= $bookB= $sheet
ABresult
0X0
100
111
361 35 my $class = "Spreadsheet::Read::Sheet";
362 $sheet =~ m/^[0-9]+$/ && $sheet >= 1 && $sheet <= $book->[0]{sheets} and
363 35 ▶ return bless $book->[$sheet] => $class;
Branch: 1 branch
BranchTrueFalseTotal
$sheet =~ /^[0-9]+$/ and $sheet >= 1 and $sheet <= $book->[0]{"sheets"} and return bless($book->[$sheet], $class) 29 6 35
Condition83%5/6
$sheet =~ /^[0-9]+$/ and $sheet >= 1 and $sheet <= $book->[0]{"sheets"}
!ll&&!rl&&r
5129
$sheet =~ /^[0-9]+$/ and $sheet >= 1
!ll&&!rl&&r
5030
MC/DC66%2/3
$sheet =~ /^[0-9]+$/ and $sheet >= 1 and $sheet <= $book->[0]{"sheets"}
$sheet =~ /^[0-9]+$/ $sheet >= 1 $sheet <= $book->[0]{"sheets"}
Truth table75%3/4
A and B and C
A= $sheet =~ /^[0-9]+$/B= $sheet >= 1C= $sheet <= $book->[0]{"sheets"}
ABCresult
0XX0
10X0
1100
1111
364 exists $book->[0]{sheet}{$sheet} and
365 6 ▶ return bless $book->[$book->[0]{sheet}{$sheet}] => $class;
Branch: 1 branch
BranchTrueFalseTotal
exists $book->[0]{"sheet"}{$sheet} and return bless($$book[$book->[0]{"sheet"}{$sheet}], $class) 1 5 6
366 5 foreach my $idx (1 .. $book->[0]{sheets}) {
367 6 ▶ $book->[$idx]{label} eq $sheet and
Branch: 1 branch
BranchTrueFalseTotal
$book->[$idx]{"label"} eq $sheet and return bless($book->[$idx], $class) 1 5 6
368 return bless $book->[$idx] => $class;
369 }
370 4 return;
371 } # sheet
372  
373 # If option "clip" is set, remove the trailing rows and
374 # columns in each sheet that contain no visible data
375 323 ▶sub _clipsheets {
Subroutine _clipsheets: called CC=46 SCAR=39.1
376 323 my ($opt, $ref) = @_;
377  
378 323 ▶ unless ($ref->[0]{sheets}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref->[0]{"sheets"}) 0 323 323
379 0 ▶ $ref->{sheet} ||= {};
Condition0%0/2
$ref->{"sheet"} ||= {}
l!l
00
MC/DC0%0/1
$ref->{"sheet"} ||= {}
$ref->{"sheet"}
Truth table0%0/2
A
A= $ref->{"sheet"}
Aresult
11
00
380 0 return $ref;
381 }
382  
383 323 my ($rc, $cl) = ($opt->{rc}, $opt->{cells});
384 323 my ($oc, $os, $oa) = ($opt->{clip}, $opt->{strip}, $opt->{attr});
385  
386 # Strip leading/trailing spaces
387 323 ▶ if ($os || $oc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os or $oc) 295 28 323
Condition100%3/3
$os or $oc
l!l&&r!l&&!r
9520028
MC/DC100%2/2
$os or $oc
$os $oc
Truth table100%3/3
A or B
A= $osB= $oc
ABresult
1X1
011
000
388 295 foreach my $sheet (1 .. $ref->[0]{sheets}) {
389 337 $ref->[$sheet]{indx} = $sheet;
390 337 my $ss = $ref->[$sheet];
391 337 ▶ $ss->{maxrow} && $ss->{maxcol} or next;
Branch: 1 branch
BranchTrueFalseTotal
$ss->{"maxrow"} and $ss->{"maxcol"} or next 330 7 337
Condition66%2/3
$ss->{"maxrow"} and $ss->{"maxcol"}
!ll&&!rl&&r
70330
MC/DC50%1/2
$ss->{"maxrow"} and $ss->{"maxcol"}
$ss->{"maxrow"} $ss->{"maxcol"}
Truth table66%2/3
A and B
A= $ss->{"maxrow"}B= $ss->{"maxcol"}
ABresult
0X0
100
111
392 330 my ($mc, $mr) = (0, 0);
393 330 foreach my $row (1 .. $ss->{maxrow}) {
394 3906 foreach my $col (1 .. $ss->{maxcol}) {
395 35943 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 30637 5306 35943
396 30637 ▶ defined $ss->{cell}[$col][$row] or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $ss->{"cell"}[$col][$row] or next 9344 21293 30637
397 9344 ▶ $os & 2 and $ss->{cell}[$col][$row] =~ s/\s+$//;
Branch: 1 branch
BranchTrueFalseTotal
$os & 2 and $ss->{"cell"}[$col][$row] =~ s/\s+$// 482 8862 9344
398 9344 ▶ $os & 1 and $ss->{cell}[$col][$row] =~ s/^\s+//;
Branch: 1 branch
BranchTrueFalseTotal
$os & 1 and $ss->{"cell"}[$col][$row] =~ s/^\s+// 380 8964 9344
399 9344 ▶ if (length $ss->{cell}[$col][$row]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ss->{"cell"}[$col][$row]) 7638 1706 9344
400 7638 ▶ $col > $mc and $mc = $col;
Branch: 1 branch
BranchTrueFalseTotal
$col > $mc and $mc = $col 998 6640 7638
401 7638 ▶ $row > $mr and $mr = $row;
Branch: 1 branch
BranchTrueFalseTotal
$row > $mr and $mr = $row 2703 4935 7638
402 }
403 }
404 14650 ▶ if ($cl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cl) 14383 267 14650
405 14383 my $cell = cr2cell ($col, $row);
406 14383 ▶ defined $ss->{$cell} or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $ss->{$cell} or next 10404 3979 14383
407 10404 ▶ $os & 2 and $ss->{$cell} =~ s/\s+$//;
Branch: 1 branch
BranchTrueFalseTotal
$os & 2 and $ss->{$cell} =~ s/\s+$// 606 9798 10404
408 10404 ▶ $os & 1 and $ss->{$cell} =~ s/^\s+//;
Branch: 1 branch
BranchTrueFalseTotal
$os & 1 and $ss->{$cell} =~ s/^\s+// 252 10152 10404
409 10404 ▶ if (length $ss->{$cell}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ss->{$cell}) 8662 1742 10404
410 8662 ▶ $col > $mc and $mc = $col;
Branch: 1 branch
BranchTrueFalseTotal
$col > $mc and $mc = $col 108 8554 8662
411 8662 ▶ $row > $mr and $mr = $row;
Branch: 1 branch
BranchTrueFalseTotal
$row > $mr and $mr = $row 414 8248 8662
412 }
413 }
414 }
415 }
416  
417 330 ▶ $oc && ($mc < $ss->{maxcol} || $mr < $ss->{maxrow}) or next;
Branch: 1 branch
BranchTrueFalseTotal
$oc and $mc < $ss->{"maxcol"} || $mr < $ss->{"maxrow"} or next 183 147 330
Condition83%5/6
$oc and $mc < $ss->{"maxcol"} || $mr < $ss->{"maxrow"}
!ll&&!rl&&r
37110183
$mc < $ss->{"maxcol"} or $mr < $ss->{"maxrow"}
l!l&&r!l&&!r
1830110
MC/DC66%2/3
$oc and $mc < $ss->{"maxcol"} || $mr < $ss->{"maxrow"}
$oc $mc < $ss->{"maxcol"} $mr < $ss->{"maxrow"}
Truth table75%3/4
A and B or C
A= $ocB= $mc < $ss->{"maxcol"}C= $mr < $ss->{"maxrow"}
ABCresult
0XX0
1000
11X1
1011
418  
419 # Remove trailing empty columns
420 183 foreach my $col (($mc + 1) .. $ss->{maxcol}) {
421 413 ▶ $rc and undef $ss->{cell}[$col];
Branch: 1 branch
BranchTrueFalseTotal
$rc and undef $ss->{"cell"}[$col] 319 94 413
422 413 ▶ $oa and undef $ss->{attr}[$col];
Branch: 1 branch
BranchTrueFalseTotal
$oa and undef $ss->{"attr"}[$col] 36 377 413
423 413 ▶ $cl or next;
Branch: 1 branch
BranchTrueFalseTotal
$cl or next 355 58 413
424 355 my $c = col2label ($col);
425 355 delete $ss->{"$c$_"} for 1 .. $ss->{maxrow};
426 }
427  
428 # Remove trailing empty rows
429 183 foreach my $row (($mr + 1) .. $ss->{maxrow}) {
430 164 foreach my $col (1 .. $mc) {
431 68 ▶ $cl and delete $ss->{cr2cell ($col, $row)};
Branch: 1 branch
BranchTrueFalseTotal
$cl and delete $$ss{cr2cell($col, $row)} 68 0 68
432 68 ▶ $rc and undef $ss->{cell} [$col][$row];
Branch: 1 branch
BranchTrueFalseTotal
$rc and undef $ss->{"cell"}[$col][$row] 68 0 68
433 68 ▶ $oa and undef $ss->{attr} [$col][$row];
Branch: 1 branch
BranchTrueFalseTotal
$oa and undef $ss->{"attr"}[$col][$row] 0 68 68
434 }
435 }
436  
437 183 ($ss->{maxrow}, $ss->{maxcol}) = ($mr, $mc);
438 }
439 }
440  
441 323 ▶ if ($opt->{pivot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"pivot"}) 2 321 323
442 2 foreach my $sheet (1 .. $ref->[0]{sheets}) {
443 2 my $ss = $ref->[$sheet];
444 2 ▶ $ss->{maxrow} || $ss->{maxcol} or next;
Branch: 1 branch
BranchTrueFalseTotal
$ss->{"maxrow"} or $ss->{"maxcol"} or next 2 0 2
Condition33%1/3
$ss->{"maxrow"} or $ss->{"maxcol"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$ss->{"maxrow"} or $ss->{"maxcol"}
$ss->{"maxrow"} $ss->{"maxcol"}
Truth table33%1/3
A or B
A= $ss->{"maxrow"}B= $ss->{"maxcol"}
ABresult
1X1
011
000
445 2 ▶ my $mx = $ss->{maxrow} > $ss->{maxcol} ? $ss->{maxrow} : $ss->{maxcol};
Branch: 1 branch
BranchTrueFalseTotal
$ss->{'maxrow'} > $ss->{'maxcol'} ? : 0 2 2
446 2 foreach my $row (2 .. $mx) {
447 36 foreach my $col (1 .. ($row - 1)) {
448 $opt->{rc} and
449 ($ss->{cell}[$col][$row], $ss->{cell}[$row][$col]) =
450 342 ▶ ($ss->{cell}[$row][$col], $ss->{cell}[$col][$row]);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"rc"} and ($ss->{"cell"}[$col][$row], $ss->{"cell"}[$row][$col]) = ($ss->{"cell"}[$row][$col], $ss->{"cell"}[$col][$row]) 342 0 342
451 $opt->{cells} and
452 ($ss->{cr2cell ($col, $row)}, $ss->{cr2cell ($row, $col)}) =
453 342 ▶ ($ss->{cr2cell ($row, $col)}, $ss->{cr2cell ($col, $row)});
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"cells"} and ($$ss{cr2cell($col, $row)}, $$ss{cr2cell($row, $col)}) = ($$ss{cr2cell($row, $col)}, $$ss{cr2cell($col, $row)}) 342 0 342
454 }
455 }
456 2 ($ss->{maxcol}, $ss->{maxrow}) = ($ss->{maxrow}, $ss->{maxcol});
457 }
458 }
459  
460 323 $ref;
461 } # _clipsheets
462  
463 # Convert a single color (index) to a color
464 1758 ▶sub _xls_color {
Subroutine _xls_color: called CC=6 SCAR=18.2
465 1758 my $clr = shift;
466 1758 ▶ defined $clr or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $clr or return undef 866 892 1758
467 866 ▶ $clr eq "#000000" and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$clr eq "#000000" and return undef 0 866 866
468 866 ▶ $clr =~ m/^#[0-9a-fA-F]+$/ and return lc $clr;
Branch: 1 branch
BranchTrueFalseTotal
$clr =~ /^#[0-9a-fA-F]+$/ and return lc $clr 0 866 866
469 866 ▶ $clr == 0 || $clr == 32767 and return undef; # Default fg color
Branch: 1 branch
BranchTrueFalseTotal
$clr == 0 || $clr == 32767 and return undef 382 484 866
Condition66%2/3
$clr == 0 or $clr == 32767
l!l&&r!l&&!r
0382484
MC/DC50%1/2
$clr == 0 or $clr == 32767
$clr == 0 $clr == 32767
Truth table66%2/3
A or B
A= $clr == 0B= $clr == 32767
ABresult
1X1
011
000
470 484 return "#" . lc Spreadsheet::ParseExcel->ColorIdxToRGB ($clr);
471 } # _xls_color
472  
473 # Convert a fill [ $pattern, $front_color, $back_color ] to a single background
474 1542 ▶sub _xls_fill {
Subroutine _xls_fill: called CC=8 SCAR=22.1
475 1542 my ($p, $fg, $bg) = @_;
476 1542 ▶ defined $p or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $p or return undef 1542 0 1542
477 1542 ▶ $p == 32767 and return undef; # Default fg color
Branch: 1 branch
BranchTrueFalseTotal
$p == 32767 and return undef 0 1542 1542
478 1542 ▶ $p == 0 && !defined $bg and return undef; # No fill bg color
Branch: 1 branch
BranchTrueFalseTotal
$p == 0 and not defined $bg and return undef 892 650 1542
Condition100%3/3
$p == 0 and not defined $bg
!ll&&!rl&&r
216434892
MC/DC100%2/2
$p == 0 and not defined $bg
$p == 0 not defined $bg
Truth table100%3/3
A and not(B)
A= $p == 0B= not defined $bg
ABresult
0X0
100
111
479 650 ▶ $p == 1 and return _xls_color ($fg);
Branch: 1 branch
BranchTrueFalseTotal
$p == 1 and return _xls_color($fg) 216 434 650
480 434 ▶ $bg < 8 || $bg > 63 and return undef; # see Workbook.pm#106
Branch: 1 branch
BranchTrueFalseTotal
$bg < 8 || $bg > 63 and return undef 434 0 434
Condition33%1/3
$bg < 8 or $bg > 63
l!l&&r!l&&!r
04340
MC/DC0%0/2
$bg < 8 or $bg > 63
$bg < 8 $bg > 63
Truth table33%1/3
A or B
A= $bg < 8B= $bg > 63
ABresult
1X1
011
000
481 0 return _xls_color ($bg);
482 } # _xls_fill
483  
484 7 ▶sub _missing_parser {
Subroutine _missing_parser: called CC=3 SCAR=11.7
485 7 my ($type, $suggest) = (shift, "");
486 7 foreach my $p (@parsers) {
487 140 ▶ $p->[0] eq lc $type or next;
Branch: 1 branch
BranchTrueFalseTotal
$p->[0] eq lc $type or next 0 140 140
488 0 $suggest = "\nPlease install $p->[1]";
489 }
490 7 "No parser for $type found$suggest\n";
491 } # _missing_parser
492  
493 37 ▶sub _txt_is_xml {
Subroutine _txt_is_xml: called CC=9 SCAR=26.0
494 # Return true if $txt is gzipped or contains XML. If we are also passed
495 # $ns_uri_of_interest, $txt must contain it in the first 1000 or so
496 # characters (but we try to search quickly rather than precisely).
497 37 my ($txt, $ns_uri_of_interest) = @_;
498  
499 37 ▶ ref $txt and return; # Can't tell (unless we assume the stream is seekable).
Branch: 1 branch
BranchTrueFalseTotal
ref $txt and return 9 28 37
500  
501 28 ▶ if ($txt =~ m/\A\037\213/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($txt =~ /\A\037\213/) 0 28 28
502 # Literal gzipped string (/usr/share/misc/magic). [this is a hack that
503 # works only because Gnumeric is the only format that uses gzip. --
504 # rgr, 13-Jan-2023]
505 0 return 1;
506 }
507  
508 28 ▶ if ($txt =~ m/\A<\?xml/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($txt =~ /\A<\?xml/) 0 28 28
509 0 ▶ $ns_uri_of_interest or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$ns_uri_of_interest or return 1 0 0 0
510 0 $ns_uri_of_interest =~ s/([^\w\d])/\\$1/g;
511 0 ▶ my $prefix = length ($txt) > 10000 ? substr $txt, 0, 1000 : $txt;
Branch: 1 branch
BranchTrueFalseTotal
length $txt > 10000 ? : 0 0 0
512 0 return $prefix =~ m/xmlns:\w+=.$ns_uri_of_interest/;
513 }
514  
515 28 ▶ $txt =~ m/\n/ and return; # safeguard for older perl versions
Branch: 1 branch
BranchTrueFalseTotal
$txt =~ /\n/ and return 7 21 28
516 21 ▶ open my $in, "<", $txt or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $txt or return 14 7 21
517 14 ▶ read $in, my $block, 1000 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $in, my $block, 1000 or return 7 7 14
518 7 return _txt_is_xml ($block, $ns_uri_of_interest);
519 } # _txt_is_xml
520  
521 376 ▶sub ReadData {
Subroutine ReadData: called CC=338 SCAR=94.1
Pod documented
522 376 ▶ my $txt = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $txt = shift() or return 373 3 376
523  
524 373 my %opt;
525 373 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 320 53 373
526 320 ▶ if (ref $_[0] eq "HASH") { %opt = %{shift @_} }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 60 260 320
elsif (@_ % 2 == 0) { } 260 0 260
527 260 elsif (@_ % 2 == 0) { %opt = @_ }
528 }
529  
530 # Aliasses
531 373 ▶ exists $opt{transpose} && !exists $opt{pivot} and $opt{pivot} = delete $opt{transpose};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"transpose"} and not exists $opt{"pivot"} and $opt{"pivot"} = delete $opt{"transpose"} 1 372 373
Condition66%2/3
exists $opt{"transpose"} and not exists $opt{"pivot"}
!ll&&!rl&&r
37201
MC/DC50%1/2
exists $opt{"transpose"} and not exists $opt{"pivot"}
exists $opt{"transpose"} not exists $opt{"pivot"}
Truth table66%2/3
A and not(B)
A= exists $opt{"transpose"}B= not exists $opt{"pivot"}
ABresult
0X0
100
111
532 373 ▶ exists $opt{trim} && !exists $opt{strip} and $opt{strip} = delete $opt{trim};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"trim"} and not exists $opt{"strip"} and $opt{"strip"} = delete $opt{"trim"} 14 359 373
Condition66%2/3
exists $opt{"trim"} and not exists $opt{"strip"}
!ll&&!rl&&r
359014
MC/DC50%1/2
exists $opt{"trim"} and not exists $opt{"strip"}
exists $opt{"trim"} not exists $opt{"strip"}
Truth table66%2/3
A and not(B)
A= exists $opt{"trim"}B= not exists $opt{"strip"}
ABresult
0X0
100
111
533  
534 373 ▶ exists $opt{rc} or $opt{rc} = $def_opts{rc};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"rc"} or $opt{"rc"} = $def_opts{"rc"} 74 299 373
535 373 ▶ exists $opt{cells} or $opt{cells} = $def_opts{cells};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"cells"} or $opt{"cells"} = $def_opts{"cells"} 39 334 373
536 373 ▶ exists $opt{attr} or $opt{attr} = $def_opts{attr};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"attr"} or $opt{"attr"} = $def_opts{"attr"} 46 327 373
537 373 ▶ exists $opt{clip} or $opt{clip} = $opt{cells};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"clip"} or $opt{"clip"} = $opt{"cells"} 130 243 373
538 373 ▶ exists $opt{strip} or $opt{strip} = $def_opts{strip};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"strip"} or $opt{"strip"} = $def_opts{"strip"} 119 254 373
539 373 ▶ exists $opt{dtfmt} or $opt{dtfmt} = $def_opts{dtfmt};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"dtfmt"} or $opt{"dtfmt"} = $def_opts{"dtfmt"} 3 370 373
540 373 ▶ exists $opt{merge} or $opt{merge} = $def_opts{merge};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{"merge"} or $opt{"merge"} = $def_opts{"merge"} 1 372 373
541  
542 # $debug = $opt{debug} || 0;
543 373 ▶ $debug = defined $opt{debug} ? $opt{debug} : $def_opts{debug};
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'debug'} ? : 7 366 373
544 373 ▶ $debug > 4 and _dump (Options => \%opt);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 4 and _dump("Options", \%opt) 7 366 373
545  
546 81 my %parser_opts = map { $_ => $opt{$_} }
547 373 grep { !exists $def_opts{$_} }
548 keys %opt;
549  
550 373 my $_parser = _parser ($opt{parser});
551  
552 373 ▶ my $io_ref = ref ($txt) =~ m/GLOB|IO/ ? $txt : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref($txt) =~ /GLOB|IO/ ? : 20 353 373
553 my $io_fil = $io_ref ? 0 : $txt =~ m/\0/ ? 0
554 70 ▶ : do { no warnings "newline"; -f $txt };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
$io_ref ? : 20 353 373
$txt =~ /\0/ ? : 1 352 353
555 373 ▶ my $io_txt = $io_ref || $io_fil ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$io_ref || $io_fil ? : 342 31 373
Condition100%3/3
$io_ref or $io_fil
l!l&&r!l&&!r
2032231
MC/DC100%2/2
$io_ref or $io_fil
$io_ref $io_fil
Truth table100%3/3
A or B
A= $io_refB= $io_fil
ABresult
1X1
011
000
556  
557 373 ▶ $io_fil && ! -s $txt and do { $@ = "$txt is empty"; return };
Branch: 1 branch
BranchTrueFalseTotal
$io_fil and not -s $txt and do { $@ = "$txt is empty"; return } 11 362 373
Condition100%3/3
$io_fil and not -s $txt
!ll&&!rl&&r
5131111
MC/DC100%2/2
$io_fil and not -s $txt
$io_fil not -s $txt
Truth table100%3/3
A and not(B)
A= $io_filB= not -s $txt
ABresult
0X0
100
111
558 362 ▶ $io_ref && eof $txt and do { $@ = "Empty stream"; return };
Branch: 1 branch
BranchTrueFalseTotal
$io_ref and eof $txt and do { $@ = "Empty stream"; return } 5 357 362
Condition100%3/3
$io_ref and eof $txt
!ll&&!rl&&r
342155
MC/DC100%2/2
$io_ref and eof $txt
$io_ref eof $txt
Truth table100%3/3
A and B
A= $io_refB= eof $txt
ABresult
0X0
100
111
559  
560 357 ▶ if ($opt{parser} ? $_parser eq "csv" : ($io_fil && $txt =~ m/\.(csv)$/i)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? $_parser eq "csv" : $io_fil && $txt =~ /\.(csv)$/i) 121 236 357
$opt{'parser'} ? : 108 249 357
Condition100%3/3
$io_fil and $txt =~ /\.(csv)$/i
!ll&&!rl&&r
2912199
MC/DC100%2/2
$io_fil and $txt =~ /\.(csv)$/i
$io_fil $txt =~ /\.(csv)$/i
Truth table100%3/3
A and B
A= $io_filB= $txt =~ /\.(csv)$/i
ABresult
0X0
100
111
561 121 ▶ $can{csv} or croak _missing_parser ("CSV");
Branch: 1 branch
BranchTrueFalseTotal
$can{"csv"} or croak(_missing_parser("CSV")) 121 0 121
562  
563 121 ▶ my $label = defined $opt{label} ? $opt{label} : $io_fil ? $txt : "IO";
Branch: 2 branches
BranchTrueFalseTotal
defined $opt{'label'} ? : 1 120 121
$io_fil ? : 108 12 120
564  
565 121 ▶ $debug and print STDERR "Opening CSV $label using $can{csv}-", $can{csv}->VERSION, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[Opening CSV $label using $can{"csv"}-], $can{"csv"}->VERSION, "\n" 0 121 121
566  
567 my @data = (
568 { type => "csv",
569 parser => $can{csv},
570 version => $can{csv}->VERSION,
571 parsers => [ {
572 type => "csv",
573 parser => $can{csv},
574 version => $can{csv}->VERSION,
575 121 }],
576 error => undef,
577 quote => '"',
578 sepchar => ',',
579 sheets => 1,
580 sheet => { $label => 1 },
581 },
582 { parser => 0,
583 label => $label,
584 maxrow => 0,
585 maxcol => 0,
586 cell => [],
587 attr => [],
588 merged => [],
589 active => 1,
590 hidden => 0,
591 },
592 );
593  
594 121 my ($sep, $quo, $in) = (",", '"');
595 121 ▶ defined $opt{sep} and $sep = $opt{sep};
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{"sep"} and $sep = $opt{"sep"} 13 108 121
596 121 ▶ defined $opt{quote} and $quo = $opt{quote};
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{"quote"} and $quo = $opt{"quote"} 13 108 121
597 121 ▶ $debug > 8 and _dump (debug => {
Branch: 1 branch
BranchTrueFalseTotal
$debug > 8 and _dump("debug", {"data", \@data, "txt", $txt, "io_ref", $io_ref, "io_fil", $io_fil}) 0 121 121
598 data => \@data, txt => $txt, io_ref => $io_ref, io_fil => $io_fil });
599 121 ▶ if ($io_fil) {
Branch: 4 branches
BranchTrueFalseTotal
if ($io_fil) { } 109 12 121
elsif ($io_ref) { } 10 2 12
elsif (ref $txt eq 'SCALAR') { } 1 1 2
elsif ($txt =~ /[\r\n,;]/) { } 1 0 1
600 109 ▶ unless (defined $opt{quote} && defined $opt{sep}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opt{"quote"} and defined $opt{"sep"}) 102 7 109
Condition100%3/3
defined $opt{"quote"} and defined $opt{"sep"}
!ll&&!rl&&r
9937
MC/DC100%2/2
defined $opt{"quote"} and defined $opt{"sep"}
defined $opt{"quote"} defined $opt{"sep"}
Truth table100%3/3
A and B
A= defined $opt{"quote"}B= defined $opt{"sep"}
ABresult
0X0
100
111
601 102 ▶ open $in, "<", $txt or return;
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $txt or return 102 0 102
602 102 my $l1 = <$in>;
603  
604 102 ▶ $quo = defined $opt{quote} ? $opt{quote} : '"';
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'quote'} ? : 3 99 102
605 $sep = # If explicitly set, use it
606 defined $opt{sep} ? $opt{sep} :
607 # otherwise start auto-detect with quoted strings
608 102 ▶ $l1 =~ m/["0-9];["0-9;]/ ? ";" :
Branch: 9 branches
BranchTrueFalseTotal
defined $opt{'sep'} ? : 0 102 102
$l1 =~ /["0-9];["0-9;]/ ? : 10 92 102
$l1 =~ /["0-9],["0-9,]/ ? : 18 74 92
$l1 =~ /["0-9]\t["0-9,]/ ? : 0 74 74
$l1 =~ /["0-9]\|["0-9,]/ ? : 0 74 74
$l1 =~ /\w;[\w;]/ ? : 0 74 74
$l1 =~ /\w,[\w,]/ ? : 1 73 74
$l1 =~ /\w\t[\w,]/ ? : 3 70 73
$l1 =~ /\w\|[\w,]/ ? : 0 70 70
609 $l1 =~ m/["0-9],["0-9,]/ ? "," :
610 $l1 =~ m/["0-9]\t["0-9,]/ ? "\t" :
611 $l1 =~ m/["0-9]\|["0-9,]/ ? "|" :
612 # If neither, then for unquoted strings
613 $l1 =~ m/\w;[\w;]/ ? ";" :
614 $l1 =~ m/\w,[\w,]/ ? "," :
615 $l1 =~ m/\w\t[\w,]/ ? "\t" :
616 $l1 =~ m/\w\|[\w,]/ ? "|" :
617 "," ;
618 102 close $in;
619 }
620 109 ▶ open $in, "<", $txt or return;
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $txt or return 109 0 109
621 }
622 elsif ($io_ref) {
623 10 $in = $txt;
624 }
625 elsif (ref $txt eq "SCALAR") {
626 1 ▶ open $in, "<", $txt or croak "Cannot open input: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $txt or croak("Cannot open input: $!") 1 0 1
627 }
628 elsif ($txt =~ m/[\r\n,;]/) {
629 1 ▶ open $in, "<", \$txt or croak "Cannot open input: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", \$txt or croak("Cannot open input: $!") 1 0 1
630 }
631 else {
632 0 warn "Input type ", ref $txt,
633 " might not be supported. Please file a ticket\n";
634 0 $in = $txt; # Now pray ...
635 }
636 121 ▶ $debug > 1 and print STDERR "CSV sep_char '$sep', quote_char '$quo'\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug > 1 and print STDERR "CSV sep_char '${sep}', quote_char '${quo}'\n" 0 121 121
637 121 ▶ if (!exists $parser_opts{strict_eol} and
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $parser_opts{"strict_eol"} and my $ka = $data[0]{"parser"}->can("known_attributes")) 119 2 121
Condition66%2/3
not exists $parser_opts{"strict_eol"} and my $ka = $data[0]{"parser"}->can("known_attributes")
!ll&&!rl&&r
20119
MC/DC50%1/2
not exists $parser_opts{"strict_eol"} and my $ka = $data[0]{"parser"}->can("known_attributes")
not exists $parser_opts{"strict_eol"} my $ka = $data[0]{"parser"}->can("known_attributes")
Truth table66%2/3
not(A) and B
A= not exists $parser_opts{"strict_eol"}B= my $ka = $data[0]{"parser"}->can("known_attributes")
ABresult
0X0
100
111
638 my $ka = $data[0]{parser}->can ("known_attributes")) {
639 119 ▶ if (grep m/^strict_eol$/ => $ka->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^strict_eol$/, &$ka()) 119 0 119
640 #use DP;::diag DDumper \@data;
641 119 ▶ unless ($data[0]{parser} =~ m/CSV_PP$/ && $data[0]{version} le "2.06") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data[0]{"parser"} =~ /CSV_PP$/ and $data[0]{"version"} le "2.06") 92 27 119
Condition66%2/3
$data[0]{"parser"} =~ /CSV_PP$/ and $data[0]{"version"} le "2.06"
!ll&&!rl&&r
92027
MC/DC50%1/2
$data[0]{"parser"} =~ /CSV_PP$/ and $data[0]{"version"} le "2.06"
$data[0]{"parser"} =~ /CSV_PP$/ $data[0]{"version"} le "2.06"
Truth table66%2/3
A and B
A= $data[0]{"parser"} =~ /CSV_PP$/B= $data[0]{"version"} le "2.06"
ABresult
0X0
100
111
642 92 $parser_opts{strict_eol} = 1;
643 }
644 }
645 }
646 my $csv = $can{csv}->new ({
647 %parser_opts,
648  
649 sep_char => ($data[0]{sepchar} = $sep),
650 121 ▶ quote_char => ($data[0]{quote} = $quo),
Branch: 1 branch
BranchTrueFalseTotal
my $csv = $can{"csv"}->new({%parser_opts, "sep_char", $data[0]{"sepchar"} = $sep, "quote_char", $data[0]{"quote"} = $quo, "keep_meta_info", 1, "binary", 1, "auto_diag", 1}) or croak("Cannot create a csv ('${sep}', '${quo}') parser!") 121 0 121
651 keep_meta_info => 1,
652 binary => 1,
653 auto_diag => 1,
654 }) or croak "Cannot create a csv ('$sep', '$quo') parser!";
655  
656 121 ▶ while (my $row = $csv->getline ($in)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $csv->getline($in)) 460 121 581
657 460 ▶ my @row = @$row or last;
Branch: 1 branch
BranchTrueFalseTotal
my(@row) = @$row or last 460 0 460
658  
659 460 my $r = ++$data[1]{maxrow};
660 460 ▶ @row > $data[1]{maxcol} and $data[1]{maxcol} = @row;
Branch: 1 branch
BranchTrueFalseTotal
@row > $data[1]{"maxcol"} and $data[1]{"maxcol"} = @row 139 321 460
661 460 foreach my $c (0 .. $#row) {
662 2630 my $val = $row[$c];
663 2630 my $cell = cr2cell ($c + 1, $r);
664 2630 ▶ $opt{rc} and $data[1]{cell}[$c + 1][$r] = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $data[1]{"cell"}[$c + 1][$r] = $val 2390 240 2630
665 2630 ▶ $opt{cells} and $data[1]{$cell} = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"cells"} and $data[1]{$cell} = $val 2390 240 2630
666 2630 ▶ $opt{attr} and $data[1]{attr}[$c + 1][$r] = { @def_attr };
Branch: 1 branch
BranchTrueFalseTotal
$opt{"attr"} and $data[1]{"attr"}[$c + 1][$r] = {@def_attr} 0 2630 2630
667 }
668 }
669 121 ▶ $parser_opts{strict_eol} and $data[1]{eolt} = $csv->eol_type;
Branch: 1 branch
BranchTrueFalseTotal
$parser_opts{"strict_eol"} and $data[1]{"eolt"} = $csv->eol_type 92 29 121
670 121 ▶ $csv->eof () or $data[0]{error} = [ $csv->error_diag ];
Branch: 1 branch
BranchTrueFalseTotal
$csv->eof or $data[0]{"error"} = [$csv->error_diag] 121 0 121
671 121 close $in;
672  
673 121 for (@{$data[1]{cell}}) {
674 804 ▶ defined or $_ = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = [] 703 101 804
675 }
676 121 return _clipsheets \%opt, [ @data ];
677 }
678  
679 236 ▶ if ($io_txt) { # && $_parser !~ m/^xlsx?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($io_txt) 29 207 236
680 29 ▶ if ( # /etc/magic: Microsoft Office Document
Branch: 4 branches
BranchTrueFalseTotal
if ($txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/x or $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/ or $txt =~ /\A\x09\x04\x06\x00\x00\x00\x10\x00/) { } 1 28 29
elsif ($txt =~ m(\APK\003\004.{4,30}(?:\[Content_Types\]\.xml|_rels/\.rels))) { } 0 28 28
elsif ($txt =~ m[\APK\003\004.{9,30}mimetypeapplication\/vnd\.oasis\.opendocument\.spreadsheet]) { } 0 28 28
elsif (not $io_ref and $txt =~ /\.xls[xm]?$/i) { } 3 25 28
Condition66%4/6
$txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/x or $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/ or $txt =~ /\A\x09\x04\x06\x00\x00\x00\x10\x00/
l!l&&r!l&&!r
1028
$txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/x or $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/
l!l&&r!l&&!r
1028
MC/DC33%1/3
$txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/x or $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/ or $txt =~ /\A\x09\x04\x06\x00\x00\x00\x10\x00/
$txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/x $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/ $txt =~ /\A\x09\x04\x06\x00\x00\x00\x10\x00/
Truth table50%2/4
A or B or C
A= $txt =~ /\A(\376\067\0\043 |\320\317\021\340\241\261\032\341 |\333\245-\0\0\0)/xB= $txt =~ /\A.{2080}Microsoft Excel 5.0 Worksheet/C= $txt =~ /\A\x09\x04\x06\x00\x00\x00\x10\x00/
ABCresult
1XX1
01X1
0011
0000
681 $txt =~ m{\A(\376\067\0\043
682 |\320\317\021\340\241\261\032\341
683 |\333\245-\0\0\0)}x
684 # /usr/share/misc/magic
685 || $txt =~ m{\A.{2080}Microsoft Excel 5.0 Worksheet}
686 || $txt =~ m{\A\x09\x04\x06\x00\x00\x00\x10\x00}
687 ) {
688 1 ▶ $can{xls} or croak _missing_parser ("XLS");
Branch: 1 branch
BranchTrueFalseTotal
$can{"xls"} or croak(_missing_parser("XLS")) 1 0 1
689 1 my $tmpfile;
690 1 ▶ if ($can{ios}) { # Do not use a temp file if IO::Scalar is available
Branch: 1 branch
BranchTrueFalseTotal
if ($can{'ios'}) { } 1 0 1
691 1 $tmpfile = \$txt;
692 }
693 else {
694 0 $tmpfile = File::Temp->new (SUFFIX => ".xls", UNLINK => 1);
695 0 binmode $tmpfile;
696 0 print $tmpfile $txt;
697 0 close $tmpfile;
698 }
699 0 ▶ open $io_ref, "<", $tmpfile or do { $@ = $!; return };
Branch: 1 branch
BranchTrueFalseTotal
open $io_ref, "<", $tmpfile or do { $@ = $!; return } 1 0 1
700 1 $io_txt = 0;
701 1 $_parser = _parser ($opt{parser} = "xls");
702 }
703 elsif ( # /usr/share/misc/magic
704 $txt =~ m{\APK\003\004.{4,30}(?:\[Content_Types\]\.xml|_rels/\.rels)}
705 ) {
706 0 ▶ $can{xlsx} or croak _missing_parser ("XLSX");
Branch: 1 branch
BranchTrueFalseTotal
$can{"xlsx"} or croak(_missing_parser("XLSX")) 0 0 0
707 0 my $tmpfile;
708 0 ▶ if ($can{ios}) { # Do not use a temp file if IO::Scalar is available
Branch: 1 branch
BranchTrueFalseTotal
if ($can{'ios'}) { } 0 0 0
709 0 $tmpfile = \$txt;
710 }
711 else {
712 0 $tmpfile = File::Temp->new (SUFFIX => ".xlsx", UNLINK => 1);
713 0 binmode $tmpfile;
714 0 print $tmpfile $txt;
715 0 close $tmpfile;
716 }
717 0 ▶ open $io_ref, "<", $tmpfile or do { $@ = $!; return };
Branch: 1 branch
BranchTrueFalseTotal
open $io_ref, "<", $tmpfile or do { $@ = $!; return } 0 0 0
718 0 $io_txt = 0;
719 0 $_parser = _parser ($opt{parser} = "xlsx");
720 }
721 elsif ( # /usr/share/misc/magic
722 $txt =~ m{\APK\003\004.{9,30}\Qmimetypeapplication/vnd.oasis.opendocument.spreadsheet}
723 ) {
724 0 ▶ $can{ods} or croak _missing_parser ("ODS");
Branch: 1 branch
BranchTrueFalseTotal
$can{"ods"} or croak(_missing_parser("ODS")) 0 0 0
725 0 my $tmpfile;
726 0 ▶ if ($can{ios}) { # Do not use a temp file if IO::Scalar is available
Branch: 1 branch
BranchTrueFalseTotal
if ($can{'ios'}) { } 0 0 0
727 0 $tmpfile = \$txt;
728 }
729 else {
730 0 $tmpfile = File::Temp->new (SUFFIX => ".ods", UNLINK => 1);
731 0 binmode $tmpfile;
732 0 print $tmpfile $txt;
733 0 close $tmpfile;
734 }
735 0 ▶ open $io_ref, "<", $tmpfile or do { $@ = $!; return };
Branch: 1 branch
BranchTrueFalseTotal
open $io_ref, "<", $tmpfile or do { $@ = $!; return } 0 0 0
736 0 $io_txt = 0;
737 0 $_parser = _parser ($opt{parser} = "ods");
738 }
739 ▶ elsif (!$io_ref && $txt =~ m/\.xls[xm]?$/i) {
Condition66%2/3
not $io_ref and $txt =~ /\.xls[xm]?$/i
!ll&&!rl&&r
0253
MC/DC50%1/2
not $io_ref and $txt =~ /\.xls[xm]?$/i
not $io_ref $txt =~ /\.xls[xm]?$/i
Truth table66%2/3
not(A) and B
A= not $io_refB= $txt =~ /\.xls[xm]?$/i
ABresult
0X0
100
111
740 3 $@ = "Cannot open $txt as file";
741 3 return;
742 }
743 }
744 233 ▶ if ($opt{parser} ? $_parser =~ m/^(?:xlsx?)$/
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? $_parser =~ /^(?:xlsx?)$/ : $io_fil && $txt =~ /\.(xls[xm]?)$/i && ($_parser = _parser($1))) 76 157 233
$opt{'parser'} ? : 87 146 233
Condition83%5/6
$io_fil and $txt =~ /\.(xls[xm]?)$/i and $_parser = _parser($1)
!ll&&!rl&&r
74072
$io_fil and $txt =~ /\.(xls[xm]?)$/i
!ll&&!rl&&r
254972
MC/DC66%2/3
$io_fil and $txt =~ /\.(xls[xm]?)$/i and $_parser = _parser($1)
$io_fil $txt =~ /\.(xls[xm]?)$/i $_parser = _parser($1)
Truth table75%3/4
A and B and C
A= $io_filB= $txt =~ /\.(xls[xm]?)$/iC= $_parser = _parser($1)
ABCresult
0XX0
10X0
1100
1111
745 : ($io_fil && $txt =~ m/\.(xls[xm]?)$/i &&
746 ($_parser = _parser ($1)))) {
747 76 ▶ my $parse_type = $_parser =~ m/x$/i ? "XLSX" : "XLS";
Branch: 1 branch
BranchTrueFalseTotal
$_parser =~ /x$/i ? : 44 32 76
748 76 ▶ my $parser = $can{lc $parse_type} or croak _missing_parser ($parse_type);
Branch: 1 branch
BranchTrueFalseTotal
my $parser = $can{lc $parse_type} or croak(_missing_parser($parse_type)) 76 0 76
749 #$debug and print STDERR __FILE__, "#", __LINE__, " | $_parser | $parser | $parse_type\n";
750 $debug and print STDERR "Opening $parse_type ", $io_ref ? "<REF>" : $txt,
751 76 ▶ " using $parser-", $can{lc $parse_type}->VERSION, "\n";
Branch: 2 branches
BranchTrueFalseTotal
$debug and print STDERR "Opening $parse_type ", $io_ref ? "<REF>" : $txt, " using $parser-", $can{lc $parse_type}->VERSION, "\n" 7 69 76
$io_ref ? : 0 7 7
752 76 ▶ $opt{passwd} and $parser_opts{Password} = $opt{passwd};
Branch: 1 branch
BranchTrueFalseTotal
$opt{"passwd"} and $parser_opts{"Password"} = $opt{"passwd"} 0 76 76
753 76 my $oBook = eval {
754 $io_ref
755 ? $parse_type eq "XLSX"
756 ? $can{xlsx} eq "Spreadsheet::XLSX"
757 ? $parser->new ($io_ref) # Spreadsheet::XLXS ($io)
758 : $can{xlsx} eq "Excel::ValueReader::XLSX"
759 ? $parser->new (xlsx => $io_ref, %parser_opts) # Excel::ValueReader::XLSX ($io / $content)
760 : $parser->new (%parser_opts)->parse ($io_ref) # Spreadsheet::ParseXLSX ($io)
761 : $parser->new (%parser_opts)->Parse ($io_ref) # Spreadsheet::ParseExcel ($io)
762 : $parse_type eq "XLSX"
763 ? $can{xlsx} eq "Spreadsheet::XLSX"
764 ? $parser->new ($txt) # Spreadsheet::XLXS ($file / $content)
765 76 ▶ : $can{xlsx} eq "Excel::ValueReader::XLSX"
Branch: 7 branches
BranchTrueFalseTotal
$io_ref ? : 4 72 76
$parse_type eq 'XLSX' ? : 0 4 4
$can{'xlsx'} eq 'Spreadsheet::XLSX' ? : 0 0 0
$can{'xlsx'} eq 'Excel::ValueReader::XLSX' ? : 0 0 0
$parse_type eq 'XLSX' ? : 44 28 72
$can{'xlsx'} eq 'Spreadsheet::XLSX' ? : 44 0 44
$can{'xlsx'} eq 'Excel::ValueReader::XLSX' ? : 0 0 0
766 ? $parser->new (xlsx => $txt, %parser_opts) # Excel::ValueReader::XLSX ($file / $content)
767 : $parser->new (%parser_opts)->parse ($txt) # Spreadsheet::ParseXLSX ($file / $content)
768 : $parser->new (%parser_opts)->Parse ($txt); # Spreadsheet::ParseExcel ($file / $content)
769 };
770 76 ▶ unless ($oBook) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oBook) 0 76 76
771 # cleanup will fail on folders with spaces.
772 0 (my $msg = $@) =~ s/ at \S+ line \d+.*//s;
773 0 croak "$parse_type parser cannot parse data: $msg";
774 }
775 76 ▶ $debug > 8 and _dump (oBook => $oBook);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 8 and _dump("oBook", $oBook) 0 76 76
776  
777 # WorkBook keys:
778 # aColor _CurSheet Format SheetCount
779 # ActiveSheet _CurSheet_ FormatStr _skip_chart
780 # Author File NotSetCell _string_contin
781 # BIFFVersion Flg1904 Object Version
782 # _buffer FmtClass PkgStr Worksheet
783 # CellHandler Font _previous_info
784  
785 my @data = ( {
786 type => lc $parse_type,
787 parser => $can{lc $parse_type},
788 version => $can{lc $parse_type}->VERSION,
789 parsers => [{
790 type => lc $parse_type,
791 parser => $can{lc $parse_type},
792 version => $can{lc $parse_type}->VERSION,
793 }],
794 error => undef,
795 76 ▶ sheets => $oBook->{SheetCount} || 0,
Condition50%1/2
$oBook->{'SheetCount'} || 0
l!l
760
MC/DC0%0/1
$oBook->{'SheetCount'} || 0
$oBook->{'SheetCount'}
Truth table50%1/2
A
A= $oBook->{'SheetCount'}
Aresult
11
00
796 sheet => {},
797 } );
798 # Overrule the default date format strings
799 my %def_fmt = (
800 0x0E => lc $opt{dtfmt}, # m-d-yy
801 76 0x0F => "d-mmm-yyyy", # d-mmm-yy
802 0x11 => "mmm-yyyy", # mmm-yy
803 0x16 => "yyyy-mm-dd hh:mm", # m-d-yy h:mm
804 );
805 76 $oBook->{FormatStr}{$_} = $def_fmt{$_} for keys %def_fmt;
806 76 my $oFmt = eval { $parse_type eq "XLSX"
807 76 ▶ ? $can{xlsx} eq "Spreadsheet::XLSX"
Branch: 2 branches
BranchTrueFalseTotal
$parse_type eq 'XLSX' ? : 44 32 76
$can{'xlsx'} eq 'Spreadsheet::XLSX' ? : 44 0 44
808 ? Spreadsheet::XLSX::Fmt2007->new
809 : Spreadsheet::ParseExcel::FmtDefault->new
810 : Spreadsheet::ParseExcel::FmtDefault->new
811 };
812  
813 76 ▶ $debug > 20 and _dump ("oBook before conversion", $oBook);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 20 and _dump("oBook before conversion", $oBook) 0 76 76
814 76 ▶ if ($can{xlsx} eq "Excel::ValueReader::XLSX" and !exists $oBook->{SheetCount}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can{"xlsx"} eq "Excel::ValueReader::XLSX" and not exists $oBook->{"SheetCount"}) 0 76 76
Condition33%1/3
$can{"xlsx"} eq "Excel::ValueReader::XLSX" and not exists $oBook->{"SheetCount"}
!ll&&!rl&&r
7600
MC/DC0%0/2
$can{"xlsx"} eq "Excel::ValueReader::XLSX" and not exists $oBook->{"SheetCount"}
$can{"xlsx"} eq "Excel::ValueReader::XLSX" not exists $oBook->{"SheetCount"}
Truth table33%1/3
A and not(B)
A= $can{"xlsx"} eq "Excel::ValueReader::XLSX"B= not exists $oBook->{"SheetCount"}
ABresult
0X0
100
111
815 0 my @sheets = $oBook->sheet_names;
816 0 $data[0]{sheet} = { map { $sheets[$_] => $_ + 1 } 0 .. $#sheets };
817 0 $data[0]{sheets} = scalar @sheets;
818  
819 0 foreach my $sheet_name (@sheets) {
820  
821 0 my $grid = $oBook->values ($sheet_name);
822  
823 0 my $sheet = {
824 label => $sheet_name,
825 minrow => 1,
826 mincol => 1,
827 indx => 1,
828 merged => [],
829 cell => [],
830 attr => [],
831 };
832 # Transpose to column vectors.
833 # The A1, B5 etc items could be added here as well.
834 0 my @c;
835 0 foreach my $r (0 .. $#$grid) {
836 0 my $row = $grid->[$r];
837 0 foreach my $c (0 .. $#$row) {
838 # add 1 for array base 1
839 0 my $val = $grid->[$r][$c];
840 0 my $cell = cr2cell ($c + 1, $r + 1);
841 0 ▶ $opt{rc} and $sheet->{cell}[$c + 1][$r + 1] = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $sheet->{"cell"}[$c + 1][$r + 1] = $val 0 0 0
842 0 ▶ $opt{cells} and $sheet->{$cell} = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"cells"} and $sheet->{$cell} = $val 0 0 0
843 0 $c[$c] = 1;
844 }
845 }
846  
847 # First entry in @t is padding so number of items
848 # is the max index.
849 0 $sheet->{maxcol} = scalar @c;
850  
851 # No padding of first entry in $grid so
852 # number of items is the array length.
853 0 $sheet->{maxrow} = @$grid;
854  
855 0 push @data => $sheet;
856 }
857 #use DP;die DDumper { oBook => $oBook, oFmt => $oFmt, data => \@data, parser_type => $parse_type };
858 }
859  
860 76 ▶ if ($parse_type eq "ODS" and !exists $oBook->{SheetCount}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse_type eq "ODS" and not exists $oBook->{"SheetCount"}) 0 76 76
Condition33%1/3
$parse_type eq "ODS" and not exists $oBook->{"SheetCount"}
!ll&&!rl&&r
7600
MC/DC0%0/2
$parse_type eq "ODS" and not exists $oBook->{"SheetCount"}
$parse_type eq "ODS" not exists $oBook->{"SheetCount"}
Truth table33%1/3
A and not(B)
A= $parse_type eq "ODS"B= not exists $oBook->{"SheetCount"}
ABresult
0X0
100
111
861 0 my $styles = delete $oBook->{_styles};
862 0 my $sheets = delete $oBook->{_sheets};
863 0 ▶ if ($sheets && ref $sheets eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sheets and ref $sheets eq "ARRAY") 0 0 0
Condition0%0/3
$sheets and ref $sheets eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$sheets and ref $sheets eq "ARRAY"
$sheets ref $sheets eq "ARRAY"
Truth table0%0/3
A and B
A= $sheetsB= ref $sheets eq "ARRAY"
ABresult
0X0
100
111
864 0 ▶ $styles = ($styles || {})->{styles} || {};
Condition0%0/4
+($styles || {})->{'styles'} || {}
l!l
00
$styles || {}
l!l
00
MC/DC0%0/1
+($styles || {})->{'styles'} || {}
$styles
Truth table0%0/2
A
A= $styles
Aresult
11
00
865 0 $data[0]{sheets} = $oBook->{SheetCount} = scalar @{$sheets};
866 0 $oBook->{Worksheet} = [];
867 0 ▶ *S::R::Sheet::get_merged_areas = sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
868 0 my $x = 0;
869 0 foreach my $sh (@{$sheets}) {
870 0 ▶ push @{$oBook->{Worksheet}} => bless {
Condition0%0/2
$sh->{'sheet_hidden'} || 0
l!l
00
MC/DC0%0/1
$sh->{'sheet_hidden'} || 0
$sh->{'sheet_hidden'}
Truth table0%0/2
A
A= $sh->{'sheet_hidden'}
Aresult
11
00
871 Name => $sh->{label},
872 Cells => [],
873 MinRow => $sh->{col_min},
874 MaxRow => $sh->{row_max},
875 MinCol => $sh->{col_min},
876 MaxCol => $sh->{row_max},
877 SheetHidden => $sh->{sheet_hidden} || 0,
878 RowHidden => $sh->{hidden_rows},
879 ColHidden => $sh->{hidden_cols},
880 0 _SheetNo => $x++,
881 } => "S::R::Sheet";
882 # header_cols
883 # header_rows
884 # print_areas
885 # sheet_hidden
886 # tab_color
887 0 ▶ *S::R::Cell::Value = sub { $_[0]{Raw} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
888 0 ▶ *S::R::Cell::is_merged = sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
889 0 my $r = 0;
890 0 foreach my $row (@{$sh->{data}}) {
891 $#$row > $oBook->{Worksheet}[-1]{MaxCol} and
892 0 ▶ $oBook->{Worksheet}[-1]{MaxCol} = $#$row;
Branch: 1 branch
BranchTrueFalseTotal
$row->$#* > $oBook->{"Worksheet"}[-1]{"MaxCol"} and $oBook->{"Worksheet"}[-1]{"MaxCol"} = $row->$#* 0 0 0
893 $oBook->{Worksheet}[-1]{Cells}[$r++] = [ map { bless {
894 Code => undef,
895 Format => $_->{format},
896 Formula => $_->{formula},
897 Hidden => undef,
898 Merged => undef,
899 # use || instead of // for now
900 # even though it is undesirable
901 Type => $_->{type} || "",
902 Val => $_->{value} || $_->{unformatted},
903 Raw => $_->{unformatted} || $_->{value},
904 _Style => $styles->{$_->{style} || ""}
905 || $_->{style},
906 # hyperlink
907 0 ▶ } => "S::R::Cell" } @{$row} ];
Condition0%0/13
$_->{'type'} || ''
l!l
00
$_->{'value'} || $_->{'unformatted'}
l!l&&r!l&&!r
000
$_->{'unformatted'} || $_->{'value'}
l!l&&r!l&&!r
000
$$styles{$_->{'style'} or ''} || $_->{'style'}
l!l&&r!l&&!r
000
$_->{'style'} || ''
l!l
00
MC/DC0%0/1
$_->{'type'} || ''
$_->{'type'}
MC/DC0%0/2
$_->{'value'} || $_->{'unformatted'}
$_->{'value'} $_->{'unformatted'}
MC/DC0%0/2
$_->{'unformatted'} || $_->{'value'}
$_->{'unformatted'} $_->{'value'}
MC/DC0%0/2
$$styles{$_->{'style'} or ''} || $_->{'style'}
$$styles{$_->{'style'} or ''} $_->{'style'}
MC/DC0%0/1
$_->{'style'} || ''
$_->{'style'}
Truth table0%0/2
A
A= $_->{'type'}
Aresult
11
00
Truth table0%0/3
A || B
A= $_->{'value'}B= $_->{'unformatted'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $_->{'unformatted'}B= $_->{'value'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $$styles{$_->{'style'} or ''}B= $_->{'style'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $_->{'style'}
Aresult
11
00
908 }
909 --$r > $oBook->{Worksheet}[-1]{MaxRow} and
910 0 ▶ $oBook->{Worksheet}[-1]{MaxRow} = $r;
Branch: 1 branch
BranchTrueFalseTotal
--$r > $oBook->{"Worksheet"}[-1]{"MaxRow"} and $oBook->{"Worksheet"}[-1]{"MaxRow"} = $r 0 0 0
911 }
912 }
913 }
914  
915 76 ▶ $debug and print STDERR "\t$data[0]{sheets} sheets\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\t$data[0]{"sheets"} sheets\n] 7 69 76
916 76 _def_gas ();
917 my $active_sheet = $oBook->get_active_sheet
918 || $oBook->{ActiveSheet}
919 76 ▶ || $oBook->{SelectedSheet};
Condition66%4/6
$oBook->get_active_sheet || $oBook->{'ActiveSheet'} || $oBook->{'SelectedSheet'}
l!l&&r!l&&!r
3073
$oBook->get_active_sheet or $oBook->{"ActiveSheet"}
l!l&&r!l&&!r
3073
MC/DC33%1/3
$oBook->get_active_sheet || $oBook->{'ActiveSheet'} || $oBook->{'SelectedSheet'}
$oBook->get_active_sheet $oBook->{"ActiveSheet"} $oBook->{'SelectedSheet'}
Truth table50%2/4
A or B || C
A= $oBook->get_active_sheetB= $oBook->{"ActiveSheet"}C= $oBook->{'SelectedSheet'}
ABCresult
1XX1
01X1
0011
0000
920 76 my $current_sheet = 0;
921 76 foreach my $oWkS (@{$oBook->{Worksheet}}) {
922 122 ▶ $debug > 8 and _dump ("oWkS", $oWkS);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 8 and _dump("oWkS", $oWkS) 0 122 122
923 122 $current_sheet++;
924 122 ▶ $opt{clip} and !defined $oWkS->{Cells} and next; # Skip empty sheets
Branch: 1 branch
BranchTrueFalseTotal
$opt{"clip"} and not defined $oWkS->{"Cells"} and next 6 116 122
Condition100%3/3
$opt{"clip"} and not defined $oWkS->{"Cells"}
!ll&&!rl&&r
24926
MC/DC100%2/2
$opt{"clip"} and not defined $oWkS->{"Cells"}
$opt{"clip"} not defined $oWkS->{"Cells"}
Truth table100%3/3
A and not(B)
A= $opt{"clip"}B= not defined $oWkS->{"Cells"}
ABresult
0X0
100
111
925 my %sheet = (
926 parser => 0,
927 label => $oWkS->{Name},
928 maxrow => 0,
929 maxcol => 0,
930 cell => [],
931 attr => [],
932 merged => [],
933 active => 0,
934 116 ▶ hidden => $oWkS->{SheetHidden} || 0,
Condition50%1/2
$oWkS->{'SheetHidden'} || 0
l!l
0116
MC/DC0%0/1
$oWkS->{'SheetHidden'} || 0
$oWkS->{'SheetHidden'}
Truth table50%1/2
A
A= $oWkS->{'SheetHidden'}
Aresult
11
00
935 );
936 # $debug and $sheet{_parser} = $oWkS;
937 116 ▶ defined $sheet{label} or $sheet{label} = "-- unlabeled --";
Branch: 1 branch
BranchTrueFalseTotal
defined $sheet{"label"} or $sheet{"label"} = "-- unlabeled --" 116 0 116
938 116 ▶ exists $oWkS->{MinRow} and $sheet{minrow} = $oWkS->{MinRow} + 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $oWkS->{"MinRow"} and $sheet{"minrow"} = $oWkS->{"MinRow"} + 1 111 5 116
939 116 ▶ exists $oWkS->{MaxRow} and $sheet{maxrow} = $oWkS->{MaxRow} + 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $oWkS->{"MaxRow"} and $sheet{"maxrow"} = $oWkS->{"MaxRow"} + 1 111 5 116
940 116 ▶ exists $oWkS->{MinCol} and $sheet{mincol} = $oWkS->{MinCol} + 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $oWkS->{"MinCol"} and $sheet{"mincol"} = $oWkS->{"MinCol"} + 1 111 5 116
941 116 ▶ exists $oWkS->{MaxCol} and $sheet{maxcol} = $oWkS->{MaxCol} + 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $oWkS->{"MaxCol"} and $sheet{"maxcol"} = $oWkS->{"MaxCol"} + 1 111 5 116
942 $sheet{merged} = [
943 14 map { $_->[0] }
944 5 sort { $a->[1] cmp $b->[1] }
945 14 map {[ $_, pack "NNNN", @$_ ]}
946 14 map {[ map { $_ + 1 } @{$_}[1,0,3,2] ]}
947 116 ▶ @{$oWkS->get_merged_areas || []}];
Condition100%2/2
$oWkS->get_merged_areas || []
l!l
9107
MC/DC100%1/1
$oWkS->get_merged_areas || []
$oWkS->get_merged_areas
Truth table100%2/2
A
A= $oWkS->get_merged_areas
Aresult
11
00
948 116 my $sheet_idx = 1 + @data;
949 116 ▶ $debug and print STDERR "\tSheet $sheet_idx '$sheet{label}' $sheet{maxrow} x $sheet{maxcol}\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\tSheet $sheet_idx '$sheet{"label"}' $sheet{"maxrow"} x $sheet{"maxcol"}\n] 15 101 116
950 116 ▶ if (defined $active_sheet) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $active_sheet) 7 109 116
951 # _SheetNo is 0-based
952 7 ▶ my $sheet_no = defined $oWkS->{_SheetNo} ? $oWkS->{_SheetNo} : $current_sheet - 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $oWkS->{'_SheetNo'} ? : 7 0 7
953 7 ▶ $sheet_no eq $active_sheet and $sheet{active} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$sheet_no eq $active_sheet and $sheet{"active"} = 1 1 6 7
954 }
955 # Sheet keys:
956 # _Book FooterMargin MinCol RightMargin
957 # BottomMargin FooterMergin MinRow RightMergin
958 # BottomMergin HCenter Name RowHeight
959 # Cells Header NoColor RowHidden
960 # ColFmtNo HeaderMargin NoOrient Scale
961 # ColHidden HeaderMergin NoPls SheetHidden
962 # ColWidth Kind Notes _SheetNo
963 # Copis Landscape PageFit SheetType
964 # DefColWidth LeftMargin PageStart SheetVersion
965 # DefRowHeight LeftMergin PaperSize TopMargin
966 # Draft LeftToRight _Pos TopMergin
967 # FitHeight MaxCol PrintGrid UsePage
968 # FitWidth MaxRow PrintHeaders VCenter
969 # Footer MergedArea Res VRes
970 116 ▶ if (exists $oWkS->{MinRow}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $oWkS->{"MinRow"}) 111 5 116
971 111 ▶ my $hiddenRows = $oWkS->{RowHidden} || [];
Condition50%1/2
$oWkS->{'RowHidden'} || []
l!l
0111
MC/DC0%0/1
$oWkS->{'RowHidden'} || []
$oWkS->{'RowHidden'}
Truth table50%1/2
A
A= $oWkS->{'RowHidden'}
Aresult
11
00
972 111 ▶ my $hiddenCols = $oWkS->{ColHidden} || [];
Condition50%1/2
$oWkS->{'ColHidden'} || []
l!l
0111
MC/DC0%0/1
$oWkS->{'ColHidden'} || []
$oWkS->{'ColHidden'}
Truth table50%1/2
A
A= $oWkS->{'ColHidden'}
Aresult
11
00
973 111 ▶ if ($opt{clip}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"clip"}) 92 19 111
974 92 my ($mr, $mc) = (-1, -1);
975 92 foreach my $r ($oWkS->{MinRow} .. $sheet{maxrow}) {
976 522 foreach my $c ($oWkS->{MinCol} .. $sheet{maxcol}) {
977 2938 ▶ my $oWkC = $oWkS->{Cells}[$r][$c] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $oWkC = $oWkS->{"Cells"}[$r][$c] or next 1717 1221 2938
978 1717 ▶ defined (my $val = $oWkC->{Val}) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $val = $oWkC->{"Val"}) or next 1717 0 1717
979 1717 ▶ $val eq "" and next;
Branch: 1 branch
BranchTrueFalseTotal
$val eq "" and next 27 1690 1717
980 1690 ▶ $r > $mr and $mr = $r;
Branch: 1 branch
BranchTrueFalseTotal
$r > $mr and $mr = $r 419 1271 1690
981 1690 ▶ $c > $mc and $mc = $c;
Branch: 1 branch
BranchTrueFalseTotal
$c > $mc and $mc = $c 298 1392 1690
982 }
983 }
984 92 ($sheet{maxrow}, $sheet{maxcol}) = ($mr + 1, $mc + 1);
985 }
986 111 foreach my $r ($oWkS->{MinRow} .. $sheet{maxrow}) {
987 602 foreach my $c ($oWkS->{MinCol} .. $sheet{maxcol}) {
988 3157 ▶ my $oWkC = $oWkS->{Cells}[$r][$c] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $oWkC = $oWkS->{"Cells"}[$r][$c] or next 1818 1339 3157
989 #defined (my $val = $oWkC->{Val}) or next;
990 1818 my $val = $oWkC->{Val};
991 1818 ▶ if (defined $val and my $enc = $oWkC->{Code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and my $enc = $oWkC->{"Code"}) 0 1818 1818
Condition33%1/3
defined $val and my $enc = $oWkC->{"Code"}
!ll&&!rl&&r
018180
MC/DC0%0/2
defined $val and my $enc = $oWkC->{"Code"}
defined $val my $enc = $oWkC->{"Code"}
Truth table33%1/3
A and B
A= defined $valB= my $enc = $oWkC->{"Code"}
ABresult
0X0
100
111
992 0 ▶ $enc eq "ucs2" and $val = decode ("utf-16be", $val);
Branch: 1 branch
BranchTrueFalseTotal
$enc eq "ucs2" and $val = &decode("utf-16be", $val) 0 0 0
993 }
994 1818 my $cell = cr2cell ($c + 1, $r + 1);
995 1818 ▶ $opt{rc} and $sheet{cell}[$c + 1][$r + 1] = $val; # Original
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $sheet{"cell"}[$c + 1][$r + 1] = $val 1794 24 1818
996  
997 1818 my $fmt;
998 1818 my $FmT = $oWkC->{Format};
999 1818 ▶ if ($FmT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FmT) { } 968 850 1818
1000 968 ▶ unless (ref $FmT) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $FmT) 130 838 968
1001 130 $fmt = $FmT;
1002 130 $FmT = {};
1003 }
1004 }
1005 else {
1006 850 $FmT = {};
1007 }
1008 1818 foreach my $attr (qw( AlignH AlignV FmtIdx Hidden Lock
1009 Wrap )) {
1010 10908 ▶ exists $FmT->{$attr} or $FmT->{$attr} = 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $FmT->{$attr} or $FmT->{$attr} = 0 5028 5880 10908
1011 }
1012 1818 ▶ exists $FmT->{Fill} or $FmT->{Fill} = [ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
exists $FmT->{"Fill"} or $FmT->{"Fill"} = [0] 838 980 1818
1013 1818 ▶ exists $FmT->{Font} or $FmT->{Font} = undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $FmT->{"Font"} or $FmT->{"Font"} = undef 838 980 1818
1014  
1015 1818 ▶ unless (defined $fmt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fmt) 1688 130 1818
1016 $fmt = $FmT->{FmtIdx}
1017 ? $oBook->{FormatStr}{$FmT->{FmtIdx}}
1018 1688 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
$FmT->{'FmtIdx'} ? : 204 1484 1688
1019 }
1020 lc $oWkC->{Type} eq "float" and
1021 1818 ▶ $oWkC->{Type} = "Numeric";
Branch: 1 branch
BranchTrueFalseTotal
lc $oWkC->{"Type"} eq "float" and $oWkC->{"Type"} = "Numeric" 0 1818 1818
1022 1818 ▶ if ($oWkC->{Type} eq "Numeric") {
Branch: 1 branch
BranchTrueFalseTotal
if ($oWkC->{"Type"} eq "Numeric") 370 1448 1818
1023 # Fixed in 0.33 and up
1024 # see Spreadsheet/ParseExcel/FmtDefault.pm
1025 $FmT->{FmtIdx} == 0x0e ||
1026 $FmT->{FmtIdx} == 0x0f ||
1027 $FmT->{FmtIdx} == 0x10 ||
1028 $FmT->{FmtIdx} == 0x11 ||
1029 $FmT->{FmtIdx} == 0x16 ||
1030 (defined $fmt && $fmt =~ m{^[dmy][-\\/dmy]*$}) and
1031 370 ▶ $oWkC->{Type} = "Date";
Branch: 1 branch
BranchTrueFalseTotal
$FmT->{"FmtIdx"} == 14 || $FmT->{"FmtIdx"} == 15 || $FmT->{"FmtIdx"} == 16 || $FmT->{"FmtIdx"} == 17 || $FmT->{"FmtIdx"} == 22 || defined $fmt && $fmt =~ m[^[dmy][-\\/dmy]*$] and $oWkC->{"Type"} = "Date" 8 362 370
Condition50%9/18
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15 or $FmT->{"FmtIdx"} == 16 or $FmT->{"FmtIdx"} == 17 or $FmT->{"FmtIdx"} == 22 or defined $fmt and $fmt =~ m[^[dmy][-\\/dmy]*$]
l!l&&r!l&&!r
08362
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15 or $FmT->{"FmtIdx"} == 16 or $FmT->{"FmtIdx"} == 17 or $FmT->{"FmtIdx"} == 22
l!l&&r!l&&!r
00370
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15 or $FmT->{"FmtIdx"} == 16 or $FmT->{"FmtIdx"} == 17
l!l&&r!l&&!r
00370
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15 or $FmT->{"FmtIdx"} == 16
l!l&&r!l&&!r
00370
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15
l!l&&r!l&&!r
00370
defined $fmt and $fmt =~ m[^[dmy][-\\/dmy]*$]
!ll&&!rl&&r
2301328
MC/DC28%2/7
$FmT->{"FmtIdx"} == 14 or $FmT->{"FmtIdx"} == 15 or $FmT->{"FmtIdx"} == 16 or $FmT->{"FmtIdx"} == 17 or $FmT->{"FmtIdx"} == 22 or defined $fmt and $fmt =~ m[^[dmy][-\\/dmy]*$]
$FmT->{"FmtIdx"} == 14 $FmT->{"FmtIdx"} == 15 $FmT->{"FmtIdx"} == 16 $FmT->{"FmtIdx"} == 17 $FmT->{"FmtIdx"} == 22 defined $fmt $fmt =~ m[^[dmy][-\\/dmy]*$]
Truth table37%3/8
A or B or C or D or E or F and G
A= $FmT->{"FmtIdx"} == 14B= $FmT->{"FmtIdx"} == 15C= $FmT->{"FmtIdx"} == 16D= $FmT->{"FmtIdx"} == 17E= $FmT->{"FmtIdx"} == 22F= defined $fmtG= $fmt =~ m[^[dmy][-\\/dmy]*$]
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
00000111
000000X0
00000100
1032 $FmT->{FmtIdx} == 0x09 ||
1033 $FmT->{FmtIdx} == 0x0a ||
1034 (defined $fmt && $fmt =~ m{^0+\.0+%$}) and
1035 370 ▶ $oWkC->{Type} = "Percentage";
Branch: 1 branch
BranchTrueFalseTotal
$FmT->{"FmtIdx"} == 9 || $FmT->{"FmtIdx"} == 10 || defined $fmt && $fmt =~ /^0+\.0+%$/ and $oWkC->{"Type"} = "Percentage" 121 249 370
Condition100%9/9
$FmT->{"FmtIdx"} == 9 or $FmT->{"FmtIdx"} == 10 or defined $fmt and $fmt =~ /^0+\.0+%$/
l!l&&r!l&&!r
2299249
$FmT->{"FmtIdx"} == 9 or $FmT->{"FmtIdx"} == 10
l!l&&r!l&&!r
193348
defined $fmt and $fmt =~ /^0+\.0+%$/
!ll&&!rl&&r
2084199
MC/DC100%4/4
$FmT->{"FmtIdx"} == 9 or $FmT->{"FmtIdx"} == 10 or defined $fmt and $fmt =~ /^0+\.0+%$/
$FmT->{"FmtIdx"} == 9 $FmT->{"FmtIdx"} == 10 defined $fmt $fmt =~ /^0+\.0+%$/
Truth table100%5/5
A or B or C and D
A= $FmT->{"FmtIdx"} == 9B= $FmT->{"FmtIdx"} == 10C= defined $fmtD= $fmt =~ /^0+\.0+%$/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1036 }
1037 1818 ▶ defined $fmt and $fmt =~ s/\\//g;
Branch: 1 branch
BranchTrueFalseTotal
defined $fmt and $fmt =~ s/\\//g 296 1522 1818
1038 $opt{cells} and # Formatted value
1039 $sheet{$cell} = $oFmt && defined $val ? $FmT && exists $def_fmt{$FmT->{FmtIdx}}
1040 1818 ▶ ? $oFmt->ValFmt ($oWkC, $oBook)
Branch: 3 branches
BranchTrueFalseTotal
$opt{"cells"} and $sheet{$cell} = $oFmt && defined $val ? $FmT && exists $def_fmt{$FmT->{"FmtIdx"}} ? $oFmt->ValFmt($oWkC, $oBook) : $oWkC->Value : undef 1792 26 1818
$oFmt && defined $val ? : 1792 0 1792
$FmT && exists $def_fmt{$FmT->{'FmtIdx'}} ? : 5 1787 1792
Condition50%3/6
$oFmt and defined $val
!ll&&!rl&&r
001792
$FmT and exists $def_fmt{$FmT->{"FmtIdx"}}
!ll&&!rl&&r
017875
MC/DC0%0/2
$oFmt and defined $val
$oFmt defined $val
MC/DC50%1/2
$FmT and exists $def_fmt{$FmT->{"FmtIdx"}}
$FmT exists $def_fmt{$FmT->{"FmtIdx"}}
Truth table33%1/3
A and B
A= $oFmtB= defined $val
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $FmTB= exists $def_fmt{$FmT->{"FmtIdx"}}
ABresult
0X0
100
111
1041 : $oWkC->Value : undef;
1042 1818 ▶ if ($opt{attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"attr"}) 1542 276 1818
1043 1542 my $FnT = $FmT->{Font};
1044 my $fmi = $FmT->{FmtIdx}
1045 ? $oBook->{FormatStr}{$FmT->{FmtIdx}}
1046 1542 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
$FmT->{'FmtIdx'} ? : 122 1420 1542
1047 1542 ▶ $fmi and $fmi =~ s/\\//g;
Branch: 1 branch
BranchTrueFalseTotal
$fmi and $fmi =~ s/\\//g 84 1458 1542
1048 1542 ▶ my $merged = (defined $oWkC->{Merged} ? $oWkC->{Merged} : $oWkC->is_merged) || 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $oWkC->{'Merged'} ? : 20 1522 1542
Condition100%2/2
(defined $oWkC->{'Merged'} ? $oWkC->{'Merged'} : $oWkC->is_merged) || 0
l!l
201522
MC/DC100%1/1
(defined $oWkC->{'Merged'} ? $oWkC->{'Merged'} : $oWkC->is_merged) || 0
(defined $oWkC->{'Merged'} ? $oWkC->{'Merged'} : $oWkC->is_merged)
Truth table100%2/2
A
A= (defined $oWkC->{'Merged'} ? $oWkC->{'Merged'} : $oWkC->is_merged)
Aresult
11
00
1049 $sheet{attr}[$c + 1][$r + 1] = {
1050 @def_attr,
1051  
1052 type => lc $oWkC->{Type},
1053 enc => $oWkC->{Code},
1054 merged => $merged,
1055 hidden => ($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 :
1056 defined $oWkC->{Hidden} ? $oWkC->{Hidden} : $FmT->{Hidden}) || 0,
1057 locked => $FmT->{Lock} || 0,
1058 format => $fmi,
1059 halign => [ undef, qw( left center right
1060 fill justify ), undef,
1061 "equal_space" ]->[$FmT->{AlignH}],
1062 valign => [ qw( top center bottom justify
1063 equal_space )]->[$FmT->{AlignV}],
1064 wrap => $FmT->{Wrap},
1065 font => $FnT->{Name},
1066 size => $FnT->{Height},
1067 bold => $FnT->{Bold},
1068 italic => $FnT->{Italic},
1069 uline => $FnT->{Underline},
1070 fgcolor => _xls_color ($FnT->{Color}),
1071 1542 bgcolor => _xls_fill (@{$FmT->{Fill}}),
1072 formula => $oWkC->{Formula},
1073 1542 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$hiddenRows->[$r] || $hiddenCols->[$c] ? : 0 1542 1542
defined $oWkC->{'Hidden'} ? : 0 1542 1542
Condition71%5/7
($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 : (defined $oWkC->{'Hidden'} ? $oWkC->{'Hidden'} : $FmT->{'Hidden'})) || 0
l!l
31539
$hiddenRows->[$r] or $hiddenCols->[$c]
l!l&&r!l&&!r
001542
$FmT->{'Lock'} || 0
l!l
644898
MC/DC0%0/2
($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 : (defined $oWkC->{'Hidden'} ? $oWkC->{'Hidden'} : $FmT->{'Hidden'})) || 0
$hiddenRows->[$r] $hiddenCols->[$c]
MC/DC100%1/1
$FmT->{'Lock'} || 0
$FmT->{'Lock'}
Truth table33%1/3
A or B
A= $hiddenRows->[$r]B= $hiddenCols->[$c]
ABresult
1X1
011
000
Truth table100%2/2
A
A= $FmT->{'Lock'}
Aresult
11
00
1074 #_dump "cell", $sheet{attr}[$c + 1][$r + 1];
1075 1542 ▶ if ($opt{merge} && $merged and
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)) 6 1536 1542
Condition83%5/6
$opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
!ll&&!rl&&r
153606
$opt{"merge"} and $merged
!ll&&!rl&&r
1526106
MC/DC66%2/3
$opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
$opt{"merge"} $merged my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
Truth table75%3/4
A and B and C
A= $opt{"merge"}B= $mergedC= my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
ABCresult
0XX0
10X0
1100
1111
1076 my $p_cell = Spreadsheet::Read::Sheet::merged_from (\%sheet, $c + 1, $r + 1)) {
1077 6 warn $p_cell;
1078 6 $sheet{attr}[$c + 1][$r + 1]{merged} = $p_cell;
1079 6 ▶ if ($cell ne $p_cell) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell ne $p_cell) 4 2 6
1080 4 my ($C, $R) = cell2cr ($p_cell);
1081 $sheet{cell}[$c + 1][$r + 1] =
1082 4 $sheet{cell}[$C][$R];
1083 4 $sheet{$cell} = $sheet{$p_cell};
1084 }
1085 }
1086 }
1087 }
1088 }
1089 }
1090 116 for (@{$sheet{cell}}) {
1091 414 ▶ defined or $_ = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = [] 325 89 414
1092 }
1093 116 push @data => { %sheet };
1094 # $data[0]{sheets}++;
1095 116 ▶ if ($sheet{label} eq "-- unlabeled --") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sheet{'label'} eq '-- unlabeled --') { } 0 116 116
1096 0 $sheet{label} = "";
1097 }
1098 else {
1099 116 $data[0]{sheet}{$sheet{label}} = $#data;
1100 }
1101 }
1102 76 return _clipsheets \%opt, [ @data ];
1103 }
1104 157 ▶ if ($opt{parser} ? $_parser =~ m/^(ods)$/
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? $_parser =~ /^(ods)$/ : $io_fil && $txt =~ /(ods)$/i && ($_parser = _parser($1)) and not +($can{$_parser} || "") =~ /sxc/i) 0 157 157
$opt{'parser'} ? : 83 74 157
Condition36%4/11
$opt{"parser"} ? $_parser =~ /^(ods)$/ : $io_fil && $txt =~ /(ods)$/i && ($_parser = _parser($1)) and not +($can{$_parser} || "") =~ /sxc/i
!ll&&!rl&&r
15700
$io_fil and $txt =~ /(ods)$/i and $_parser = _parser($1)
!ll&&!rl&&r
7400
$io_fil and $txt =~ /(ods)$/i
!ll&&!rl&&r
25490
$can{$_parser} || ''
l!l
00
MC/DC0%0/2
$opt{"parser"} ? $_parser =~ /^(ods)$/ : $io_fil && $txt =~ /(ods)$/i && ($_parser = _parser($1)) and not +($can{$_parser} || "") =~ /sxc/i
$opt{"parser"} ? $_parser =~ /^(ods)$/ : $io_fil && $txt =~ /(ods)$/i && ($_parser = _parser($1)) $can{$_parser}
MC/DC0%0/3
$io_fil and $txt =~ /(ods)$/i and $_parser = _parser($1)
$io_fil $txt =~ /(ods)$/i $_parser = _parser($1)
Truth table33%1/3
A and not(B)
A= $opt{"parser"} ? $_parser =~ /^(ods)$/ : $io_fil && $txt =~ /(ods)$/i && ($_parser = _parser($1))B= $can{$_parser}
ABresult
0X0
110
101
Truth table50%2/4
A and B and C
A= $io_filB= $txt =~ /(ods)$/iC= $_parser = _parser($1)
ABCresult
0XX0
10X0
1100
1111
1105 : ($io_fil && $txt =~ m/(ods)$/i &&
1106 ($_parser = _parser ($1)))
1107 and ($can{$_parser} || "") !~ m/sxc/i) {
1108 0 my $parse_type = "ODS";
1109 0 ▶ my $parser = $can{lc $parse_type} or
Branch: 1 branch
BranchTrueFalseTotal
my $parser = $can{lc $parse_type} or croak(_missing_parser($parse_type)) 0 0 0
1110 croak _missing_parser ($parse_type);
1111 #$debug and print STDERR __FILE__, "#", __LINE__, " | $_parser | $parser | $parse_type\n";
1112 $debug and print STDERR "Opening $parse_type ", $io_ref ? "<REF>" : $txt,
1113 0 ▶ " using $parser-", $can{lc $parse_type}->VERSION, "\n";
Branch: 2 branches
BranchTrueFalseTotal
$debug and print STDERR "Opening $parse_type ", $io_ref ? "<REF>" : $txt, " using $parser-", $can{lc $parse_type}->VERSION, "\n" 0 0 0
$io_ref ? : 0 0 0
1114 0 ▶ $opt{passwd} and $parser_opts{Password} = $opt{passwd};
Branch: 1 branch
BranchTrueFalseTotal
$opt{"passwd"} and $parser_opts{"Password"} = $opt{"passwd"} 0 0 0
1115 0 my $oBook = eval {
1116 0 ▶ $io_ref
Branch: 1 branch
BranchTrueFalseTotal
$io_ref ? : 0 0 0
1117 ? $parser->new (readonly => 1, %parser_opts)->parse ($io_ref)
1118 : $parser->new (readonly => 1, %parser_opts)->parse ($txt)
1119 };
1120 0 ▶ unless ($oBook) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oBook) 0 0 0
1121 # cleanup will fail on folders with spaces.
1122 0 (my $msg = $@) =~ s/ at \S+ line \d+.*//s;
1123 0 croak "$parse_type parser cannot parse data: $msg";
1124 }
1125 0 ▶ $debug > 8 and _dump (oBook => $oBook);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 8 and _dump("oBook", $oBook) 0 0 0
1126  
1127 my @data = ( {
1128 type => lc $parse_type,
1129 parser => $can{lc $parse_type},
1130 version => $can{lc $parse_type}->VERSION,
1131 parsers => [{
1132 type => lc $parse_type,
1133 parser => $can{lc $parse_type},
1134 0 version => $can{lc $parse_type}->VERSION,
1135 }],
1136 error => undef,
1137 sheets => scalar $oBook->worksheets,
1138 sheet => {},
1139 } );
1140 # $debug and $data[0]{_parser} = $oBook;
1141  
1142 0 ▶ $debug and print STDERR "\t$data[0]{sheets} sheets\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\t$data[0]{"sheets"} sheets\n] 0 0 0
1143 0 _def_gas ();
1144 0 my $active_sheet = $oBook->get_active_sheet;
1145 0 my $current_sheet = 0;
1146 0 foreach my $oWkS ($oBook->worksheets) {
1147 0 $current_sheet++;
1148 0 ▶ $opt{clip} && $oWkS->row_max < $oWkS->row_min
Branch: 1 branch
BranchTrueFalseTotal
$opt{"clip"} and $oWkS->row_max < $oWkS->row_min and $oWkS->col_max < $oWkS->col_min and next 0 0 0
Condition0%0/6
$opt{"clip"} and $oWkS->row_max < $oWkS->row_min and $oWkS->col_max < $oWkS->col_min
!ll&&!rl&&r
000
$opt{"clip"} and $oWkS->row_max < $oWkS->row_min
!ll&&!rl&&r
000
MC/DC0%0/3
$opt{"clip"} and $oWkS->row_max < $oWkS->row_min and $oWkS->col_max < $oWkS->col_min
$opt{"clip"} $oWkS->row_max < $oWkS->row_min $oWkS->col_max < $oWkS->col_min
Truth table0%0/4
A and B and C
A= $opt{"clip"}B= $oWkS->row_max < $oWkS->row_minC= $oWkS->col_max < $oWkS->col_min
ABCresult
0XX0
10X0
1100
1111
1149 && $oWkS->col_max < $oWkS->col_min and next; # Skip empty sheets
1150 0 my %sheet = (
1151 parser => 0,
1152 label => $oWkS->label,
1153 maxrow => $oWkS->row_max+1,
1154 maxcol => $oWkS->col_max+1,
1155 cell => [],
1156 attr => [],
1157 merged => [],
1158 active => 0,
1159 hidden => 0,
1160 );
1161 # $debug and $sheet{_parser} = $oWkS;
1162 0 ▶ defined $sheet{label} or $sheet{label} = "-- unlabeled --";
Branch: 1 branch
BranchTrueFalseTotal
defined $sheet{"label"} or $sheet{"label"} = "-- unlabeled --" 0 0 0
1163 $sheet{merged} = [
1164 0 map { $_->[0] }
1165 0 sort { $a->[1] cmp $b->[1] }
1166 0 map {[ $_, pack "NNNN", @$_ ]}
1167 0 map {[ map { $_ + 1 } @{$_}[1,0,3,2] ]}
1168 0 ▶ @{$oWkS->get_merged_areas || []}];
Condition0%0/2
$oWkS->get_merged_areas || []
l!l
00
MC/DC0%0/1
$oWkS->get_merged_areas || []
$oWkS->get_merged_areas
Truth table0%0/2
A
A= $oWkS->get_merged_areas
Aresult
11
00
1169 0 my $sheet_idx = 1 + @data;
1170 0 ▶ $debug and print STDERR "\tSheet $sheet_idx '$sheet{label}' $sheet{maxrow} x $sheet{maxcol}\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\tSheet $sheet_idx '$sheet{"label"}' $sheet{"maxrow"} x $sheet{"maxcol"}\n] 0 0 0
1171 0 ▶ if (defined $active_sheet) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $active_sheet) 0 0 0
1172 0 my $sheet_no = $current_sheet - 1;
1173 0 ▶ $sheet_no eq $active_sheet and $sheet{active} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$sheet_no eq $active_sheet and $sheet{"active"} = 1 0 0 0
1174 }
1175 0 ▶ my $hiddenRows = $oWkS->hidden_rows || [];
Condition0%0/2
$oWkS->hidden_rows || []
l!l
00
MC/DC0%0/1
$oWkS->hidden_rows || []
$oWkS->hidden_rows
Truth table0%0/2
A
A= $oWkS->hidden_rows
Aresult
11
00
1176 0 ▶ my $hiddenCols = $oWkS->hidden_cols || [];
Condition0%0/2
$oWkS->hidden_cols || []
l!l
00
MC/DC0%0/1
$oWkS->hidden_cols || []
$oWkS->hidden_cols
Truth table0%0/2
A
A= $oWkS->hidden_cols
Aresult
11
00
1177 0 ▶ if ($opt{clip}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"clip"}) 0 0 0
1178 0 my ($mr, $mc) = (-1, -1);
1179 0 foreach my $r ($oWkS->row_min .. $sheet{maxrow}-1) {
1180 0 foreach my $c ($oWkS->col_min .. $sheet{maxcol}-1) {
1181 0 ▶ my $oWkC = $oWkS->get_cell($r, $c) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $oWkC = $oWkS->get_cell($r, $c) or next 0 0 0
1182 0 ▶ defined (my $val = $oWkC->value) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $val = $oWkC->value) or next 0 0 0
1183 0 ▶ $val eq "" and next;
Branch: 1 branch
BranchTrueFalseTotal
$val eq "" and next 0 0 0
1184 0 ▶ $r > $mr and $mr = $r;
Branch: 1 branch
BranchTrueFalseTotal
$r > $mr and $mr = $r 0 0 0
1185 0 ▶ $c > $mc and $mc = $c;
Branch: 1 branch
BranchTrueFalseTotal
$c > $mc and $mc = $c 0 0 0
1186 }
1187 }
1188 0 ($sheet{maxrow}, $sheet{maxcol}) = ($mr + 1, $mc + 1);
1189 }
1190 0 foreach my $r ($oWkS->row_min .. $sheet{maxrow}) {
1191 0 foreach my $c ($oWkS->col_min .. $sheet{maxcol}) {
1192 0 ▶ my $oWkC = $oWkS->get_cell($r, $c) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $oWkC = $oWkS->get_cell($r, $c) or next 0 0 0
1193 0 my $val = $oWkC->unformatted;
1194 #if (defined $val and my $enc = $oWkC->{Code}) {
1195 # $enc eq "ucs2" and $val = decode ("utf-16be", $val);
1196 # }
1197 0 my $cell = cr2cell ($c + 1, $r + 1);
1198 0 ▶ $opt{rc} and $sheet{cell}[$c + 1][$r + 1] = $val; # Original
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $sheet{"cell"}[$c + 1][$r + 1] = $val 0 0 0
1199  
1200 0 my $fmt;
1201 0 my $styleName = $oWkC->style;
1202 0 my $FmT;
1203 0 ▶ if ($styleName && defined (my $s = $oBook->_styles->{$styleName})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($styleName and defined(my $s = $oBook->_styles->{$styleName})) 0 0 0
Condition0%0/3
$styleName and defined(my $s = $oBook->_styles->{$styleName})
!ll&&!rl&&r
000
MC/DC0%0/2
$styleName and defined(my $s = $oBook->_styles->{$styleName})
$styleName defined(my $s = $oBook->_styles->{$styleName})
Truth table0%0/3
A and B
A= $styleNameB= defined(my $s = $oBook->_styles->{$styleName})
ABresult
0X0
100
111
1204 0 $fmt = $s;
1205 }
1206  
1207 0 ▶ defined $fmt and $fmt =~ s/\\//g;
Branch: 1 branch
BranchTrueFalseTotal
defined $fmt and $fmt =~ s/\\//g 0 0 0
1208 $opt{cells} and # Formatted value
1209 0 ▶ $sheet{$cell} = defined $val ? $oWkC->value : undef;
Branch: 2 branches
BranchTrueFalseTotal
$opt{"cells"} and $sheet{$cell} = defined $val ? $oWkC->value : undef 0 0 0
defined $val ? : 0 0 0
1210 0 ▶ if ($opt{attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"attr"}) 0 0 0
1211 # my $FnT = $FmT ? $FmT->{font_face} : undef;
1212 0 my $fmi;
1213 #my $fmi = $FmT ? $FmT->{FmtIdx}
1214 # ? $oBook->{FormatStr}{$FmT->{FmtIdx}}
1215 # : undef;
1216 #$fmi and $fmi =~ s/\\//g;
1217 0 ▶ my $type = $oWkC->type || '';
Condition0%0/2
$oWkC->type || ''
l!l
00
MC/DC0%0/1
$oWkC->type || ''
$oWkC->type
Truth table0%0/2
A
A= $oWkC->type
Aresult
11
00
1218 0 ▶ $type eq "float" and $type = "numeric";
Branch: 1 branch
BranchTrueFalseTotal
$type eq "float" and $type = "numeric" 0 0 0
1219  
1220 0 ▶ my $merged = $oWkC->is_merged || 0;
Condition0%0/2
$oWkC->is_merged || 0
l!l
00
MC/DC0%0/1
$oWkC->is_merged || 0
$oWkC->is_merged
Truth table0%0/2
A
A= $oWkC->is_merged
Aresult
11
00
1221 0 ▶ $sheet{attr}[$c + 1][$r + 1] = {
Branch: 2 branches
BranchTrueFalseTotal
$hiddenRows->[$r] || $hiddenCols->[$c] ? : 0 0 0
$oWkC->is_hidden ? : 0 0 0
Condition0%0/5
($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 : ($oWkC->is_hidden ? $oWkC->is_hidden : undef)) || 0
l!l
00
$hiddenRows->[$r] or $hiddenCols->[$c]
l!l&&r!l&&!r
000
MC/DC0%0/2
($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 : ($oWkC->is_hidden ? $oWkC->is_hidden : undef)) || 0
$hiddenRows->[$r] $hiddenCols->[$c]
Truth table0%0/3
A or B
A= $hiddenRows->[$r]B= $hiddenCols->[$c]
ABresult
1X1
011
000
1222 @def_attr,
1223  
1224 type => $type,
1225 # enc => $oWkC->{Code},
1226 merged => $merged,
1227 hidden => ($hiddenRows->[$r] || $hiddenCols->[$c] ? 1 :
1228 $oWkC->is_hidden ? $oWkC->is_hidden : undef) || 0,
1229 # locked => $FmT->{Lock} || 0,
1230 format => $fmi,
1231 # halign => [ undef, qw( left center right
1232 # fill justify ), undef,
1233 # "equal_space" ]->[$FmT->{AlignH}],
1234 # valign => [ qw( top center bottom justify
1235 # equal_space )]->[$FmT->{AlignV}],
1236 # wrap => $FmT->{Wrap},
1237 # font => $FnT->{Name},
1238 # size => $FnT->{Height},
1239 # bold => $FnT->{Bold},
1240 # italic => $FnT->{Italic},
1241 # uline => $FnT->{Underline},
1242 # fgcolor => _xls_color ($FnT->{Color}),
1243 # bgcolor => _xls_fill (@{$FmT->{Fill}}),
1244 formula => $oWkC->formula,
1245 };
1246 #_dump "cell", $sheet{attr}[$c + 1][$r + 1];
1247 0 ▶ if ($opt{merge} && $merged and
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)) 0 0 0
Condition0%0/6
$opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
!ll&&!rl&&r
000
$opt{"merge"} and $merged
!ll&&!rl&&r
000
MC/DC0%0/3
$opt{"merge"} and $merged and my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
$opt{"merge"} $merged my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
Truth table0%0/4
A and B and C
A= $opt{"merge"}B= $mergedC= my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)
ABCresult
0XX0
10X0
1100
1111
1248 my $p_cell = Spreadsheet::Read::Sheet::merged_from(\%sheet, $c + 1, $r + 1)) {
1249 0 $sheet{attr}[$c + 1][$r + 1]{merged} = $p_cell;
1250 0 ▶ if ($cell ne $p_cell) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell ne $p_cell) 0 0 0
1251 0 my ($C, $R) = cell2cr ($p_cell);
1252 $sheet{cell}[$c + 1][$r + 1] =
1253 0 $sheet{cell}[$C][$R];
1254 0 $sheet{$cell} = $sheet{$p_cell};
1255 }
1256 }
1257 }
1258 }
1259 }
1260 0 for (@{$sheet{cell}}) {
1261 0 ▶ defined or $_ = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = [] 0 0 0
1262 }
1263 0 push @data, { %sheet };
1264 0 ▶ if ($sheet{label} eq "-- unlabeled --") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sheet{'label'} eq '-- unlabeled --') { } 0 0 0
1265 0 $sheet{label} = "";
1266 }
1267 else {
1268 0 $data[0]{sheet}{$sheet{label}} = $#data;
1269 }
1270 }
1271 0 return _clipsheets \%opt, [ @data ];
1272 }
1273  
1274 157 ▶ if ($opt{parser} ? _parser ($opt{parser}) eq "sc"
Branch: 3 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? _parser($opt{"parser"}) eq "sc" : ($io_fil ? $txt =~ /\.sc$/ : $txt =~ /^# .*SquirrelCalc/)) 126 31 157
$opt{'parser'} ? : 83 74 157
$io_fil ? : 49 25 74
1275 : $io_fil
1276 ? $txt =~ m/\.sc$/
1277 : $txt =~ m/^# .*SquirrelCalc/) {
1278 126 ▶ if ($io_ref) {
Branch: 2 branches
BranchTrueFalseTotal
if ($io_ref) { } 2 124 126
elsif ($io_fil) { } 122 2 124
1279 2 local $/;
1280 2 my $x = <$txt>;
1281 2 $txt = $x;
1282 }
1283 elsif ($io_fil) {
1284 122 local $/;
1285 122 ▶ open my $sc, "<", $txt or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $sc, "<", $txt or return 122 0 122
1286 122 $txt = <$sc>;
1287 122 close $sc;
1288 }
1289 126 ▶ $txt =~ m/\S/ or return;
Branch: 1 branch
BranchTrueFalseTotal
$txt =~ /\S/ or return 126 0 126
1290 126 ▶ my $label = defined $opt{label} ? $opt{label} : "sheet";
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'label'} ? : 0 126 126
1291 126 my @data = (
1292 { type => "sc",
1293 parser => "Spreadsheet::Read",
1294 version => $VERSION,
1295 parsers => [{
1296 type => "sc",
1297 parser => "Spreadsheet::Read",
1298 version => $VERSION,
1299 }],
1300 error => undef,
1301 sheets => 1,
1302 sheet => { $label => 1 },
1303 },
1304 { parser => 0,
1305 label => $label,
1306 maxrow => 0,
1307 maxcol => 0,
1308 cell => [],
1309 attr => [],
1310 merged => [],
1311 active => 1,
1312 hidden => 0,
1313 },
1314 );
1315  
1316 126 for (split m/\s*[\r\n]\s*/, $txt) {
1317 36918 ▶ if (m/^dimension.*of ([0-9]+) rows.*of ([0-9]+) columns/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^dimension.*of ([0-9]+) rows.*of ([0-9]+) columns/i) 126 36792 36918
1318 126 @{$data[1]}{qw(maxrow maxcol)} = ($1, $2);
1319 126 next;
1320 }
1321 36792 ▶ s/^r([0-9]+)c([0-9]+)\s*=\s*// or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^r([0-9]+)c([0-9]+)\s*=\s*// or next 9702 27090 36792
1322 9702 my ($c, $r) = map { $_ + 1 } $2, $1;
1323 9702 ▶ if (m/.* \{(.*)}$/ or m/"(.*)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/.* \{(.*)}$/ or /"(.*)"/) 7434 2268 9702
Condition66%2/3
/.* \{(.*)}$/ or /"(.*)"/
l!l&&r!l&&!r
074342268
MC/DC50%1/2
/.* \{(.*)}$/ or /"(.*)"/
/.* \{(.*)}$/ /"(.*)"/
Truth table66%2/3
A or B
A= /.* \{(.*)}$/B= /"(.*)"/
ABresult
1X1
011
000
1324 7434 my $cell = cr2cell ($c, $r);
1325 7434 ▶ $opt{rc} and $data[1]{cell}[$c][$r] = $1;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $data[1]{"cell"}[$c][$r] = $1 6372 1062 7434
1326 7434 ▶ $opt{cells} and $data[1]{$cell} = $1;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"cells"} and $data[1]{$cell} = $1 7434 0 7434
1327 7434 ▶ $opt{attr} and $data[1]{attr}[$c + 1][$r] = { @def_attr };
Branch: 1 branch
BranchTrueFalseTotal
$opt{"attr"} and $data[1]{"attr"}[$c + 1][$r] = {@def_attr} 708 6726 7434
1328 7434 next;
1329 }
1330 # Now only formula's remain. Ignore for now
1331 # r67c7 = [P2L] 2*(1000*r67c5-60)
1332 }
1333 126 for (@{$data[1]{cell}}) {
1334 972 ▶ defined or $_ = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = [] 864 108 972
1335 }
1336 126 return _clipsheets \%opt, [ @data ];
1337 }
1338  
1339 31 ▶ if ($opt{parser} ? _parser ($opt{parser}) eq "gnumeric"
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? _parser($opt{"parser"}) eq "gnumeric" : _txt_is_xml($txt, "http://www.gnumeric.org/v10.dtd")) 0 31 31
$opt{'parser'} ? : 1 30 31
1340 : _txt_is_xml ($txt, "http://www.gnumeric.org/v10.dtd")) {
1341 0 ▶ $can{gnumeric} or croak _missing_parser ("gnumeric");
Branch: 1 branch
BranchTrueFalseTotal
$can{"gnumeric"} or croak(_missing_parser("gnumeric")) 0 0 0
1342  
1343 my $gnm = $can{gnumeric}->new (%parser_opts,
1344 attr => $opt{attr},
1345 cells => $opt{cells},
1346 merge => $opt{merge},
1347 rc => $opt{rc},
1348 0 gzipped_p => $opt{gzipped_p});
1349 0 return _clipsheets \%opt, $gnm->parse ($txt);
1350 }
1351  
1352 31 ▶ if ($opt{parser} ? _parser ($opt{parser}) eq "sxc"
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{"parser"} ? _parser($opt{"parser"}) eq "sxc" : $txt =~ /^<\?xml/ || -f $txt) 7 24 31
$opt{'parser'} ? : 1 30 31
Condition66%2/3
$txt =~ /^<\?xml/ or -f $txt
l!l&&r!l&&!r
0723
MC/DC50%1/2
$txt =~ /^<\?xml/ or -f $txt
$txt =~ /^<\?xml/ -f $txt
Truth table66%2/3
A or B
A= $txt =~ /^<\?xml/B= -f $txt
ABresult
1X1
011
000
1353 : ($txt =~ m/^<\?xml/ or -f $txt)) {
1354 7 ▶ $can{sxc} or croak _missing_parser ("SXC");
Branch: 1 branch
BranchTrueFalseTotal
$can{"sxc"} or croak(_missing_parser("SXC")) 0 7 7
1355  
1356 0 ▶ ref $txt && $can{sxc}->VERSION <= 0.23 and
Branch: 1 branch
BranchTrueFalseTotal
ref $txt and $can{"sxc"}->VERSION <= "0.23" and croak("Sorry, references as input are not supported by Spreadsheet::ReadSXC before 0.23") 0 0 0
Condition0%0/3
ref $txt and $can{"sxc"}->VERSION <= "0.23"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $txt and $can{"sxc"}->VERSION <= "0.23"
ref $txt $can{"sxc"}->VERSION <= "0.23"
Truth table0%0/3
A and B
A= ref $txtB= $can{"sxc"}->VERSION <= "0.23"
ABresult
0X0
100
111
1357 croak ("Sorry, references as input are not supported by Spreadsheet::ReadSXC before 0.23");
1358  
1359 0 my $using = "using $can{sxc}-" . $can{sxc}->VERSION;
1360 0 my $sxc_options = { %parser_opts, OrderBySheet => 1 }; # New interface 0.20 and up
1361 0 my $sxc;
1362 0 ▶ if ($txt =~ m/\.(sxc|ods)$/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($txt =~ /\.(sxc|ods)$/i) { } 0 0 0
elsif (ref $txt) { } 0 0 0
elsif ($txt =~ /\.xml$/i) { } 0 0 0
elsif (not $txt =~ /^<\?xml/i and -f $txt) { } 0 0 0
1363 0 ▶ $debug and print STDERR "Opening \U$1\E $txt $using\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR "Opening \U$1\E $txt $using\n" 0 0 0
1364 0 ▶ $debug and print STDERR __FILE__, "#", __LINE__, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR __FILE__, "#", __LINE__, "\n" 0 0 0
1365 0 ▶ $sxc = Spreadsheet::ReadSXC::read_sxc ($txt, $sxc_options) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sxc = Spreadsheet::ReadSXC::read_sxc($txt, $sxc_options) or return 0 0 0
1366 }
1367 # treat all refs as a filehandle
1368 elsif (ref $txt) {
1369 0 ▶ $debug and print STDERR "Opening SXC filehandle\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR "Opening SXC filehandle\n" 0 0 0
1370 0 ▶ $sxc = Spreadsheet::ReadSXC::read_sxc_fh ($txt, $sxc_options) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sxc = Spreadsheet::ReadSXC::read_sxc_fh($txt, $sxc_options) or return 0 0 0
1371 }
1372 elsif ($txt =~ m/\.xml$/i) {
1373 0 ▶ $debug and print STDERR "Opening XML $txt $using\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR "Opening XML $txt $using\n" 0 0 0
1374 0 ▶ $sxc = Spreadsheet::ReadSXC::read_xml_file ($txt, $sxc_options) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sxc = Spreadsheet::ReadSXC::read_xml_file($txt, $sxc_options) or return 0 0 0
1375 }
1376 # need to test on pattern to prevent stat warning
1377 # on filename with newline
1378 ▶ elsif ($txt !~ m/^<\?xml/i and -f $txt) {
Condition0%0/3
not $txt =~ /^<\?xml/i and -f $txt
!ll&&!rl&&r
000
MC/DC0%0/2
not $txt =~ /^<\?xml/i and -f $txt
not $txt =~ /^<\?xml/i -f $txt
Truth table0%0/3
not(A) and B
A= not $txt =~ /^<\?xml/iB= -f $txt
ABresult
0X0
100
111
1379 0 ▶ $debug and print STDERR "Opening XML $txt $using\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR "Opening XML $txt $using\n" 0 0 0
1380 0 ▶ open my $f, "<", $txt or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $txt or return 0 0 0
1381 0 local $/;
1382 0 $txt = <$f>;
1383 0 close $f;
1384 }
1385 0 ▶ !$sxc && $txt =~ m/^<\?xml/i and
Branch: 1 branch
BranchTrueFalseTotal
not $sxc and $txt =~ /^<\?xml/i and $sxc = Spreadsheet::ReadSXC::read_xml_string($txt, $sxc_options) 0 0 0
Condition0%0/3
not $sxc and $txt =~ /^<\?xml/i
!ll&&!rl&&r
000
MC/DC0%0/2
not $sxc and $txt =~ /^<\?xml/i
not $sxc $txt =~ /^<\?xml/i
Truth table0%0/3
not(A) and B
A= not $sxcB= $txt =~ /^<\?xml/i
ABresult
0X0
100
111
1386 $sxc = Spreadsheet::ReadSXC::read_xml_string ($txt, $sxc_options);
1387 0 ▶ $debug > 8 and _dump (sxc => $sxc);
Branch: 1 branch
BranchTrueFalseTotal
$debug > 8 and _dump("sxc", $sxc) 0 0 0
1388 0 ▶ if ($sxc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sxc) 0 0 0
1389 0 my @data = ( {
1390 type => "sxc",
1391 parser => "Spreadsheet::ReadSXC",
1392 version => $Spreadsheet::ReadSXC::VERSION,
1393 parsers => [{
1394 type => "sxc",
1395 parser => "Spreadsheet::ReadSXC",
1396 version => $Spreadsheet::ReadSXC::VERSION,
1397 }],
1398 error => undef,
1399 sheets => 0,
1400 sheet => {},
1401 } );
1402 my @sheets = ref $sxc eq "HASH" # < 0.20
1403 ? map {
1404 { label => $_,
1405 0 data => $sxc->{$_},
1406 }
1407 } keys %$sxc
1408 0 ▶ : @{$sxc};
Branch: 1 branch
BranchTrueFalseTotal
ref $sxc eq 'HASH' ? : 0 0 0
1409 0 foreach my $sheet (@sheets) {
1410 0 ▶ my @sheet = @{$sheet->{data} || []};
Condition0%0/2
$sheet->{'data'} || []
l!l
00
MC/DC0%0/1
$sheet->{'data'} || []
$sheet->{'data'}
Truth table0%0/2
A
A= $sheet->{'data'}
Aresult
11
00
1411 my %sheet = (
1412 parser => 0,
1413 label => $sheet->{label},
1414 0 maxrow => scalar @sheet,
1415 maxcol => 0,
1416 cell => [],
1417 attr => [],
1418 merged => [],
1419 active => 0,
1420 hidden => 0,
1421 );
1422 0 my $sheet_idx = 1 + @data;
1423 0 ▶ $debug and print STDERR "\tSheet $sheet_idx '$sheet{label}' $sheet{maxrow} rows\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\tSheet $sheet_idx '$sheet{"label"}' $sheet{"maxrow"} rows\n] 0 0 0
1424 0 foreach my $r (0 .. $#sheet) {
1425 0 ▶ my @row = @{$sheet[$r]} or next;
Branch: 1 branch
BranchTrueFalseTotal
my(@row) = @{$sheet[$r];} or next 0 0 0
1426 0 foreach my $c (0 .. $#row) {
1427 0 ▶ defined (my $val = $row[$c]) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $val = $row[$c]) or next 0 0 0
1428 0 my $C = $c + 1;
1429 0 ▶ $C > $sheet{maxcol} and $sheet{maxcol} = $C;
Branch: 1 branch
BranchTrueFalseTotal
$C > $sheet{"maxcol"} and $sheet{"maxcol"} = $C 0 0 0
1430 0 my $cell = cr2cell ($C, $r + 1);
1431 0 ▶ $opt{rc} and $sheet{cell}[$C][$r + 1] = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"rc"} and $sheet{"cell"}[$C][$r + 1] = $val 0 0 0
1432 0 ▶ $opt{cells} and $sheet{$cell} = $val;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"cells"} and $sheet{$cell} = $val 0 0 0
1433 0 ▶ $opt{attr} and $sheet{attr}[$C][$r + 1] = { @def_attr };
Branch: 1 branch
BranchTrueFalseTotal
$opt{"attr"} and $sheet{"attr"}[$C][$r + 1] = {@def_attr} 0 0 0
1434 }
1435 }
1436 0 for (@{$sheet{cell}}) {
1437 0 ▶ defined or $_ = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = [] 0 0 0
1438 }
1439 0 ▶ $debug and print STDERR "\tSheet $sheet_idx '$sheet{label}' $sheet{maxrow} x $sheet{maxcol}\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print STDERR qq[\tSheet $sheet_idx '$sheet{"label"}' $sheet{"maxrow"} x $sheet{"maxcol"}\n] 0 0 0
1440 0 push @data, { %sheet };
1441 0 $data[0]{sheets}++;
1442 0 $data[0]{sheet}{$sheet->{label}} = $#data;
1443 }
1444 0 return _clipsheets \%opt, [ @data ];
1445 }
1446 }
1447  
1448 24 ▶ if (!ref $txt and $txt =~ m/\.\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $txt and $txt =~ /\.\w+$/) 6 18 24
Condition100%3/3
not ref $txt and $txt =~ /\.\w+$/
!ll&&!rl&&r
996
MC/DC100%2/2
not ref $txt and $txt =~ /\.\w+$/
not ref $txt $txt =~ /\.\w+$/
Truth table100%3/3
not(A) and B
A= not ref $txtB= $txt =~ /\.\w+$/
ABresult
0X0
100
111
1449 # Return (localized) system message
1450 6 ▶ open my $fh, "<", $txt and
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $txt and croak("I can open file $txt, but I do not know how to parse it\n") 1 5 6
1451 croak "I can open file $txt, but I do not know how to parse it\n";
1452  
1453 5 $@ = $!;
1454 }
1455  
1456 23 return;
1457 } # ReadData
1458  
1459 2 ▶sub add {
Subroutine add: called CC=15 SCAR=33.0
Pod documented
1460 2 my $book = shift;
1461 2 ▶ my $r = ReadData (@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $r = ReadData(@_) or return 2 0 2
1462 $book && (ref $book eq "ARRAY" ||
1463 2 ▶ ref $book eq __PACKAGE__) && $book->[0]{sheets} or return $r;
Branch: 1 branch
BranchTrueFalseTotal
$book and ref $book eq "ARRAY" || ref $book eq __PACKAGE__ and $book->[0]{"sheets"} or return $r 2 0 2
Condition33%3/9
$book and ref $book eq "ARRAY" || ref $book eq __PACKAGE__ and $book->[0]{"sheets"}
!ll&&!rl&&r
002
$book and ref $book eq "ARRAY" || ref $book eq __PACKAGE__
!ll&&!rl&&r
002
ref $book eq "ARRAY" or ref $book eq __PACKAGE__
l!l&&r!l&&!r
020
MC/DC0%0/4
$book and ref $book eq "ARRAY" || ref $book eq __PACKAGE__ and $book->[0]{"sheets"}
$book ref $book eq "ARRAY" ref $book eq __PACKAGE__ $book->[0]{"sheets"}
Truth table16%1/6
A and B or C and D
A= $bookB= ref $book eq "ARRAY"C= ref $book eq __PACKAGE__D= $book->[0]{"sheets"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1464  
1465 2 my $c1 = $book->[0];
1466 2 my $c2 = $r->[0];
1467  
1468 2 ▶ unless ($c1->{parsers}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c1->{"parsers"}) 0 2 2
1469 0 $c1->{parsers}[0]{$_} = $c1->{$_} for qw( type parser version );
1470 0 $book->[$_]{parser} = 0 for 1 .. $c1->{sheets};
1471 }
1472 2 my ($pidx) = (grep { my $p = $c1->{parsers}[$_];
1473 $p->{type} eq $c2->{type} &&
1474 $p->{parser} eq $c2->{parser} &&
1475 2 ▶ $p->{version} eq $c2->{version} } 0 .. $#{$c1->{parsers}});
Condition33%2/6
$p->{'type'} eq $c2->{'type'} && $p->{'parser'} eq $c2->{'parser'} && $p->{'version'} eq $c2->{'version'}
!ll&&!rl&&r
002
$p->{"type"} eq $c2->{"type"} and $p->{"parser"} eq $c2->{"parser"}
!ll&&!rl&&r
002
MC/DC0%0/3
$p->{'type'} eq $c2->{'type'} && $p->{'parser'} eq $c2->{'parser'} && $p->{'version'} eq $c2->{'version'}
$p->{"type"} eq $c2->{"type"} $p->{"parser"} eq $c2->{"parser"} $p->{'version'} eq $c2->{'version'}
Truth table25%1/4
A and B && C
A= $p->{"type"} eq $c2->{"type"}B= $p->{"parser"} eq $c2->{"parser"}C= $p->{'version'} eq $c2->{'version'}
ABCresult
0XX0
10X0
1100
1111
1476 2 ▶ unless (defined $pidx) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pidx) 0 2 2
1477 0 $pidx = scalar @{$c1->{parsers}};
1478 0 $c1->{parsers}[$pidx]{$_} = $c2->{$_} for qw( type parser version );
1479 }
1480  
1481 0 foreach my $sn (sort { $c2->{sheet}{$a} <=> $c2->{sheet}{$b} } keys %{$c2->{sheet}}) {
1482 2 my $s = $sn;
1483 2 my $v = 2;
1484 2 ▶ while (exists $c1->{sheet}{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $c1->{"sheet"}{$s}) 1 2 3
1485 1 $s = $sn."[".$v++."]";
1486 }
1487 2 $c1->{sheet}{$s} = $c1->{sheets} + $c2->{sheet}{$sn};
1488 2 $r->[$c2->{sheet}{$sn}]{parser} = $pidx;
1489 2 push @$book, $r->[$c2->{sheet}{$sn}];
1490 }
1491 2 $c1->{sheets} += $c2->{sheets};
1492  
1493 2 return $book;
1494 } # add
1495  
1496 package Spreadsheet::Read::Attribute;
1497  
1498 70 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
1499 70 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
1500  
1501 33 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
1502 33 my $self = shift;
1503 33 (my $attr = $AUTOLOAD) =~ s/.*:://;
1504 33 $self->{$attr};
1505 } # AUTOLOAD
1506  
1507 package Spreadsheet::Read::Sheet;
1508  
1509 70 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
1510  
1511 55 ▶sub cell {
Subroutine cell: called CC=7 SCAR=22.5
1512 55 my ($sheet, @id) = @_;
1513 @id == 2 && $id[0] =~ m/^[0-9]+$/ && $id[1] =~ m/^[0-9]+$/ and
1514 55 ▶ return $sheet->{cell}[$id[0]][$id[1]];
Branch: 1 branch
BranchTrueFalseTotal
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/ and return $sheet->{"cell"}[$id[0]][$id[1]] 28 27 55
Condition66%4/6
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
!ll&&!rl&&r
27028
@id == 2 and $id[0] =~ /^[0-9]+$/
!ll&&!rl&&r
27028
MC/DC33%1/3
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
@id == 2 $id[0] =~ /^[0-9]+$/ $id[1] =~ /^[0-9]+$/
Truth table50%2/4
A and B and C
A= @id == 2B= $id[0] =~ /^[0-9]+$/C= $id[1] =~ /^[0-9]+$/
ABCresult
0XX0
10X0
1100
1111
1515 @id && $id[0] && exists $sheet->{$id[0]} and
1516 27 ▶ return $sheet->{$id[0]};
Branch: 1 branch
BranchTrueFalseTotal
@id and $id[0] and exists $$sheet{$id[0]} and return $$sheet{$id[0]} 27 0 27
Condition33%2/6
@id and $id[0] and exists $$sheet{$id[0]}
!ll&&!rl&&r
0027
@id and $id[0]
!ll&&!rl&&r
0027
MC/DC0%0/3
@id and $id[0] and exists $$sheet{$id[0]}
@id $id[0] exists $$sheet{$id[0]}
Truth table25%1/4
A and B and C
A= @idB= $id[0]C= exists $$sheet{$id[0]}
ABCresult
0XX0
10X0
1100
1111
1517 } # cell
1518  
1519 26 ▶sub attr {
Subroutine attr: called CC=7 SCAR=22.0
1520 26 my ($sheet, @id) = @_;
1521 26 my $class = "Spreadsheet::Read::Attribute";
1522 @id == 2 && $id[0] =~ m/^[0-9]+$/ && $id[1] =~ m/^[0-9]+$/ and
1523 26 ▶ return bless $sheet->{attr}[$id[0]][$id[1]] => $class;
Branch: 1 branch
BranchTrueFalseTotal
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/ and return bless($sheet->{"attr"}[$id[0]][$id[1]], $class) 12 14 26
Condition66%4/6
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
!ll&&!rl&&r
14012
@id == 2 and $id[0] =~ /^[0-9]+$/
!ll&&!rl&&r
14012
MC/DC33%1/3
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
@id == 2 $id[0] =~ /^[0-9]+$/ $id[1] =~ /^[0-9]+$/
Truth table50%2/4
A and B and C
A= @id == 2B= $id[0] =~ /^[0-9]+$/C= $id[1] =~ /^[0-9]+$/
ABCresult
0XX0
10X0
1100
1111
1524 14 ▶ if (@id && $id[0] && exists $sheet->{$id[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@id and $id[0] and exists $$sheet{$id[0]}) 14 0 14
Condition33%2/6
@id and $id[0] and exists $$sheet{$id[0]}
!ll&&!rl&&r
0014
@id and $id[0]
!ll&&!rl&&r
0014
MC/DC0%0/3
@id and $id[0] and exists $$sheet{$id[0]}
@id $id[0] exists $$sheet{$id[0]}
Truth table25%1/4
A and B and C
A= @idB= $id[0]C= exists $$sheet{$id[0]}
ABCresult
0XX0
10X0
1100
1111
1525 14 my ($c, $r) = $sheet->cell2cr ($id[0]);
1526 14 return bless $sheet->{attr}[$c][$r] => $class;
1527 }
1528 0 undef;
1529 } # attr
1530  
1531 2 ▶sub maxrow {
Subroutine maxrow: called CC=1 SCAR=0.0
1532 2 my $sheet = shift;
1533 2 return $sheet->{maxrow};
1534 } # maxrow
1535  
1536 2 ▶sub maxcol {
Subroutine maxcol: called CC=1 SCAR=0.0
1537 2 my $sheet = shift;
1538 2 return $sheet->{maxcol};
1539 } # maxrow
1540  
1541 1 ▶sub col2label {
Subroutine col2label: called CC=2 SCAR=7.2
1542 1 ▶ $_[0] =~ m/::/ and shift; # class unused
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /::/ and shift() 1 0 1
1543 1 return Spreadsheet::Read::col2label (@_);
1544 } # col2label
1545  
1546 3 ▶sub label2col {
Subroutine label2col: called CC=2 SCAR=6.9
1547 3 ▶ $_[0] =~ m/::/ and shift; # class unused
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /::/ and shift() 1 2 3
1548 3 return Spreadsheet::Read::label2col (@_);
1549 } # label2col
1550  
1551 50 ▶sub cr2cell {
Subroutine cr2cell: called CC=2 SCAR=6.9
1552 50 ▶ $_[0] =~ m/::/ and shift; # class unused
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /::/ and shift() 40 10 50
1553 50 return Spreadsheet::Read::cr2cell (@_);
1554 } # cr2cell
1555  
1556 41 ▶sub cell2cr {
Subroutine cell2cr: called CC=2 SCAR=6.9
1557 41 ▶ $_[0] =~ m/::/ and shift; # class unused
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /::/ and shift() 30 11 41
1558 41 return Spreadsheet::Read::cell2cr (@_);
1559 } # cell2cr
1560  
1561 2 ▶sub label {
Subroutine label: called CC=2 SCAR=6.9
1562 2 my ($sheet, $label) = @_;
1563 2 ▶ defined $label and $sheet->{label} = $label;
Branch: 1 branch
BranchTrueFalseTotal
defined $label and $sheet->{"label"} = $label 1 1 2
1564 2 return $sheet->{label};
1565 } # label
1566  
1567 1 ▶sub active {
Subroutine active: called CC=1 SCAR=0.0
1568 1 my $sheet = shift;
1569 1 return $sheet->{active};
1570 } # label
1571  
1572 1 ▶sub hidden {
Subroutine hidden: called CC=1 SCAR=0.0
1573 1 my $sheet = shift;
1574 1 return $sheet->{hidden};
1575 } # label
1576  
1577 # my @row = $sheet->cellrow (1);
1578 4 ▶sub cellrow {
Subroutine cellrow: called CC=4 SCAR=13.9
1579 4 my ($sheet, $row) = @_;
1580 4 ▶ defined $row && $row > 0 && $row <= $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $row and $row > 0 and $row <= $sheet->{"maxrow"} or return 1 3 4
Condition83%5/6
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
!ll&&!rl&&r
211
defined $row and $row > 0
!ll&&!rl&&r
022
MC/DC66%2/3
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
defined $row $row > 0 $row <= $sheet->{"maxrow"}
Truth table75%3/4
A and B and C
A= defined $rowB= $row > 0C= $row <= $sheet->{"maxrow"}
ABCresult
0XX0
10X0
1100
1111
1581 1 my $s = $sheet->{cell};
1582 1 map { $s->[$_][$row] } 1..$sheet->{maxcol};
1583 } # cellrow
1584  
1585 # my @row = $sheet->row (1);
1586 4 ▶sub row {
Subroutine row: called CC=4 SCAR=13.9
1587 4 my ($sheet, $row) = @_;
1588 4 ▶ defined $row && $row > 0 && $row <= $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $row and $row > 0 and $row <= $sheet->{"maxrow"} or return 1 3 4
Condition83%5/6
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
!ll&&!rl&&r
211
defined $row and $row > 0
!ll&&!rl&&r
022
MC/DC66%2/3
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
defined $row $row > 0 $row <= $sheet->{"maxrow"}
Truth table75%3/4
A and B and C
A= defined $rowB= $row > 0C= $row <= $sheet->{"maxrow"}
ABCresult
0XX0
10X0
1100
1111
1589 1 map { $sheet->{$sheet->cr2cell ($_, $row)} } 1..$sheet->{maxcol};
1590 } # row
1591  
1592 # my @col = $sheet->cellcolumn (1);
1593 # my @col = $sheet->cellcolumn ("A");
1594 5 ▶sub cellcolumn {
Subroutine cellcolumn: called CC=5 SCAR=16.1
1595 5 my ($sheet, $col) = @_;
1596 5 ▶ defined $col or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $col or return 5 0 5
1597 5 ▶ $col =~ m/^[A-Za-z]+$/ and $col = label2col ($col);
Branch: 1 branch
BranchTrueFalseTotal
$col =~ /^[A-Za-z]+$/ and $col = label2col($col) 1 4 5
1598 5 ▶ $col > 0 && $col <= $sheet->{maxcol} or return;
Branch: 1 branch
BranchTrueFalseTotal
$col > 0 and $col <= $sheet->{"maxcol"} or return 2 3 5
Condition100%3/3
$col > 0 and $col <= $sheet->{"maxcol"}
!ll&&!rl&&r
212
MC/DC100%2/2
$col > 0 and $col <= $sheet->{"maxcol"}
$col > 0 $col <= $sheet->{"maxcol"}
Truth table100%3/3
A and B
A= $col > 0B= $col <= $sheet->{"maxcol"}
ABresult
0X0
100
111
1599 2 my $s = $sheet->{cell};
1600 2 map { $s->[$col][$_] } 1..$sheet->{maxrow};
1601 } # cellcolumn
1602  
1603 # my @col = $sheet->column (1);
1604 # my @col = $sheet->column ("A");
1605 5 ▶sub column {
Subroutine column: called CC=5 SCAR=16.1
1606 5 my ($sheet, $col) = @_;
1607 5 ▶ defined $col or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $col or return 5 0 5
1608 5 ▶ $col =~ m/^[A-Za-z]+$/ and $col = label2col ($col);
Branch: 1 branch
BranchTrueFalseTotal
$col =~ /^[A-Za-z]+$/ and $col = label2col($col) 1 4 5
1609 5 ▶ $col > 0 && $col <= $sheet->{maxcol} or return;
Branch: 1 branch
BranchTrueFalseTotal
$col > 0 and $col <= $sheet->{"maxcol"} or return 2 3 5
Condition100%3/3
$col > 0 and $col <= $sheet->{"maxcol"}
!ll&&!rl&&r
212
MC/DC100%2/2
$col > 0 and $col <= $sheet->{"maxcol"}
$col > 0 $col <= $sheet->{"maxcol"}
Truth table100%3/3
A and B
A= $col > 0B= $col <= $sheet->{"maxcol"}
ABresult
0X0
100
111
1610 2 map { $sheet->{$sheet->cr2cell ($col, $_)} } 1..$sheet->{maxrow};
1611 } # column
1612  
1613 # my $arrayref = $sheet->cellrange ("B3:D5");
1614 # my $arrayref = $sheet->cellrange (2, 3, 4, 5);
1615 5 ▶sub cellrange {
Subroutine cellrange: called CC=14 SCAR=27.2
1616 5 my ($sheet, @r) = @_;
1617 5 my $s = $sheet->{cell};
1618 5 ▶ if (@r == 1 && $r[0] =~ m/^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/) 2 3 5
Condition66%2/3
@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
!ll&&!rl&&r
302
MC/DC50%1/2
@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
@r == 1 $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
Truth table66%2/3
A and B
A= @r == 1B= $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
ABresult
0X0
100
111
1619 2 my ($cl, $rt) = cell2cr (uc $1);
1620 2 my ($cr, $rb) = cell2cr (uc $2);
1621 2 $cl = min ($sheet->{maxcol}, max (1, $cl));
1622 2 $rt = min ($sheet->{maxrow}, max (1, $rt));
1623 2 $cr = min ($sheet->{maxcol}, max (1, $cr));
1624 2 $rb = min ($sheet->{maxrow}, max (1, $rb));
1625 2 my @R;
1626 2 foreach my $c ($cl .. $cr) {
1627 3 push @R => [ map { $s->[$c][$_] } $rt .. $rb ];
1628 }
1629 2 return \@R;
1630 }
1631 3 ▶ if (@r == 4 and $r[0] =~ m/^-?[0-9]+/ && $r[1] =~ m/^-?[0-9]+/
Branch: 1 branch
BranchTrueFalseTotal
if (@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)) 3 0 3
Condition33%4/12
@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
MC/DC0%0/5
@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)
@r == 4 $r[0] =~ /^-?[0-9]+/ $r[1] =~ /^-?[0-9]+/ $r[2] =~ /^-?[0-9]+/ $r[3] =~ /^-?[0-9]+/
Truth table16%1/6
A and B and C and D and E
A= @r == 4B= $r[0] =~ /^-?[0-9]+/C= $r[1] =~ /^-?[0-9]+/D= $r[2] =~ /^-?[0-9]+/E= $r[3] =~ /^-?[0-9]+/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1632 && $r[2] =~ m/^-?[0-9]+/ && $r[3] =~ m/^-?[0-9]+/) {
1633 3 ▶ $r[0] < 0 and $r[0] = $sheet->{maxcol} + 1 + $r[0];
Branch: 1 branch
BranchTrueFalseTotal
$r[0] < 0 and $r[0] = $sheet->{"maxcol"} + 1 + $r[0] 1 2 3
1634 3 ▶ $r[1] < 0 and $r[1] = $sheet->{maxrow} + 1 + $r[1];
Branch: 1 branch
BranchTrueFalseTotal
$r[1] < 0 and $r[1] = $sheet->{"maxrow"} + 1 + $r[1] 1 2 3
1635 3 ▶ $r[2] < 0 and $r[2] = $sheet->{maxcol} + 1 + $r[2];
Branch: 1 branch
BranchTrueFalseTotal
$r[2] < 0 and $r[2] = $sheet->{"maxcol"} + 1 + $r[2] 1 2 3
1636 3 ▶ $r[3] < 0 and $r[3] = $sheet->{maxrow} + 1 + $r[3];
Branch: 1 branch
BranchTrueFalseTotal
$r[3] < 0 and $r[3] = $sheet->{"maxrow"} + 1 + $r[3] 1 2 3
1637 3 $r[0] = min ($sheet->{maxcol}, max (1, $r[0]));
1638 3 $r[1] = min ($sheet->{maxrow}, max (1, $r[1]));
1639 3 $r[2] = min ($sheet->{maxcol}, max (1, $r[2]));
1640 3 $r[3] = min ($sheet->{maxrow}, max (1, $r[3]));
1641 3 my @R;
1642 3 foreach my $c ($r[0] .. $r[2]) {
1643 4 push @R => [ map { $s->[$c][$_] } $r[1] .. $r[3] ];
1644 }
1645 3 return \@R;
1646 }
1647 } # cellrange
1648  
1649 # my $hashref = $sheet->range ("A3:D7")
1650 # my $hashref = $sheet->range (1, 3, 4, 7)
1651 5 ▶sub range {
Subroutine range: called CC=16 SCAR=28.7
1652 5 my ($sheet, @r, $R) = @_;
1653 5 ▶ if (@r == 1 && $r[0] =~ m/^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/) 2 3 5
Condition66%2/3
@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
!ll&&!rl&&r
302
MC/DC50%1/2
@r == 1 and $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
@r == 1 $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
Truth table66%2/3
A and B
A= @r == 1B= $r[0] =~ /^([A-Za-z]+[0-9]+):([A-Za-z]+[0-9]+)$/
ABresult
0X0
100
111
1654 2 my ($cl, $rt) = cell2cr (uc $1);
1655 2 my ($cr, $rb) = cell2cr (uc $2);
1656 2 $cl = min ($sheet->{maxcol}, max (1, $cl));
1657 2 $rt = min ($sheet->{maxrow}, max (1, $rt));
1658 2 $cr = min ($sheet->{maxcol}, max (1, $cr));
1659 2 $rb = min ($sheet->{maxrow}, max (1, $rb));
1660 2 foreach my $c ($cl .. $cr) {
1661 3 foreach my $r ($rt .. $rb) {
1662 5 my $C = $sheet->cr2cell ($c, $r);
1663 5 $R->{$C} = $sheet->{$C};
1664 }
1665 }
1666 2 return $R;
1667 }
1668 3 ▶ if (@r == 4 and $r[0] =~ m/^-?[0-9]+/ && $r[1] =~ m/^-?[0-9]+/
Branch: 1 branch
BranchTrueFalseTotal
if (@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)) 3 0 3
Condition33%4/12
@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
$r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/
!ll&&!rl&&r
003
MC/DC0%0/5
@r == 4 and ($r[0] =~ /^-?[0-9]+/ and $r[1] =~ /^-?[0-9]+/ and $r[2] =~ /^-?[0-9]+/ and $r[3] =~ /^-?[0-9]+/)
@r == 4 $r[0] =~ /^-?[0-9]+/ $r[1] =~ /^-?[0-9]+/ $r[2] =~ /^-?[0-9]+/ $r[3] =~ /^-?[0-9]+/
Truth table16%1/6
A and B and C and D and E
A= @r == 4B= $r[0] =~ /^-?[0-9]+/C= $r[1] =~ /^-?[0-9]+/D= $r[2] =~ /^-?[0-9]+/E= $r[3] =~ /^-?[0-9]+/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1669 && $r[2] =~ m/^-?[0-9]+/ && $r[3] =~ m/^-?[0-9]+/) {
1670 3 ▶ $r[0] < 0 and $r[0] = $sheet->{maxcol} + 1 + $r[0];
Branch: 1 branch
BranchTrueFalseTotal
$r[0] < 0 and $r[0] = $sheet->{"maxcol"} + 1 + $r[0] 1 2 3
1671 3 ▶ $r[1] < 0 and $r[1] = $sheet->{maxrow} + 1 + $r[1];
Branch: 1 branch
BranchTrueFalseTotal
$r[1] < 0 and $r[1] = $sheet->{"maxrow"} + 1 + $r[1] 1 2 3
1672 3 ▶ $r[2] < 0 and $r[2] = $sheet->{maxcol} + 1 + $r[2];
Branch: 1 branch
BranchTrueFalseTotal
$r[2] < 0 and $r[2] = $sheet->{"maxcol"} + 1 + $r[2] 1 2 3
1673 3 ▶ $r[3] < 0 and $r[3] = $sheet->{maxrow} + 1 + $r[3];
Branch: 1 branch
BranchTrueFalseTotal
$r[3] < 0 and $r[3] = $sheet->{"maxrow"} + 1 + $r[3] 1 2 3
1674 3 $r[0] = min ($sheet->{maxcol}, max (1, $r[0]));
1675 3 $r[1] = min ($sheet->{maxrow}, max (1, $r[1]));
1676 3 $r[2] = min ($sheet->{maxcol}, max (1, $r[2]));
1677 3 $r[3] = min ($sheet->{maxrow}, max (1, $r[3]));
1678 3 foreach my $c ($r[0] .. $r[2]) {
1679 4 foreach my $r ($r[1] .. $r[3]) {
1680 6 my $C = $sheet->cr2cell ($c, $r);
1681 6 $R->{$C} = $sheet->{$C};
1682 }
1683 }
1684 3 return $R;
1685 }
1686 } # range
1687  
1688 # Convert {cell}'s [column][row] to a [row][column] list
1689 # my @rows = $sheet->rows ();
1690 1 ▶sub rows {
Subroutine rows: called CC=1 SCAR=0.0
1691 1 my $sheet = shift;
1692 1 my $s = $sheet->{cell};
1693  
1694 map {
1695 5 my $r = $_;
1696 5 [ map { $s->[$_][$r] } 1..$sheet->{maxcol} ];
1697 1 } 1..$sheet->{maxrow};
1698 } # rows
1699  
1700 17 ▶sub merged_from {
Subroutine merged_from: called CC=19 SCAR=31.4
1701 17 my ($sheet, @id, $col, $row) = @_;
1702 17 ▶ my $ma = $sheet->{merged} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ma = $sheet->{"merged"} or return 17 0 17
1703 17 ▶ if (@id == 2 && $id[0] =~ m/^[0-9]+$/ && $id[1] =~ m/^[0-9]+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/) { } 10 7 17
elsif (@id and $id[0] and exists $$sheet{$id[0]}) { } 3 4 7
Condition66%4/6
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
!ll&&!rl&&r
7010
@id == 2 and $id[0] =~ /^[0-9]+$/
!ll&&!rl&&r
7010
MC/DC33%1/3
@id == 2 and $id[0] =~ /^[0-9]+$/ and $id[1] =~ /^[0-9]+$/
@id == 2 $id[0] =~ /^[0-9]+$/ $id[1] =~ /^[0-9]+$/
Truth table50%2/4
A and B and C
A= @id == 2B= $id[0] =~ /^[0-9]+$/C= $id[1] =~ /^[0-9]+$/
ABCresult
0XX0
10X0
1100
1111
1704 10 ($col, $row) = @id;
1705 }
1706 ▶ elsif (@id && $id[0] && exists $sheet->{$id[0]}) {
Condition50%3/6
@id and $id[0] and exists $$sheet{$id[0]}
!ll&&!rl&&r
043
@id and $id[0]
!ll&&!rl&&r
007
MC/DC33%1/3
@id and $id[0] and exists $$sheet{$id[0]}
@id $id[0] exists $$sheet{$id[0]}
Truth table50%2/4
A and B and C
A= @idB= $id[0]C= exists $$sheet{$id[0]}
ABCresult
0XX0
10X0
1100
1111
1707 3 ($col, $row) = cell2cr ($id[0]);
1708 }
1709 17 ▶ defined $row && $row > 0 && $row <= $sheet->{maxrow} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $row and $row > 0 and $row <= $sheet->{"maxrow"} or return 12 5 17
Condition83%5/6
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
!ll&&!rl&&r
4112
defined $row and $row > 0
!ll&&!rl&&r
4013
MC/DC66%2/3
defined $row and $row > 0 and $row <= $sheet->{"maxrow"}
defined $row $row > 0 $row <= $sheet->{"maxrow"}
Truth table75%3/4
A and B and C
A= defined $rowB= $row > 0C= $row <= $sheet->{"maxrow"}
ABCresult
0XX0
10X0
1100
1111
1710 12 ▶ defined $col && $col > 0 && $col <= $sheet->{maxcol} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $col and $col > 0 and $col <= $sheet->{"maxcol"} or return 12 0 12
Condition33%2/6
defined $col and $col > 0 and $col <= $sheet->{"maxcol"}
!ll&&!rl&&r
0012
defined $col and $col > 0
!ll&&!rl&&r
0012
MC/DC0%0/3
defined $col and $col > 0 and $col <= $sheet->{"maxcol"}
defined $col $col > 0 $col <= $sheet->{"maxcol"}
Truth table25%1/4
A and B and C
A= defined $colB= $col > 0C= $col <= $sheet->{"maxcol"}
ABCresult
0XX0
10X0
1100
1111
1711 12 foreach my $range (@{$ma}) {
1712 22 my ($ctl, $rtl, $cbr, $rbr) = @{$range};
1713 22 ▶ $col >= $ctl && $col <= $cbr or next;
Branch: 1 branch
BranchTrueFalseTotal
$col >= $ctl and $col <= $cbr or next 12 10 22
Condition100%3/3
$col >= $ctl and $col <= $cbr
!ll&&!rl&&r
2812
MC/DC100%2/2
$col >= $ctl and $col <= $cbr
$col >= $ctl $col <= $cbr
Truth table100%3/3
A and B
A= $col >= $ctlB= $col <= $cbr
ABresult
0X0
100
111
1714 12 ▶ $row >= $rtl && $row <= $rbr or next;
Branch: 1 branch
BranchTrueFalseTotal
$row >= $rtl and $row <= $rbr or next 10 2 12
Condition66%2/3
$row >= $rtl and $row <= $rbr
!ll&&!rl&&r
2010
MC/DC50%1/2
$row >= $rtl and $row <= $rbr
$row >= $rtl $row <= $rbr
Truth table66%2/3
A and B
A= $row >= $rtlB= $row <= $rbr
ABresult
0X0
100
111
1715 10 return cr2cell ($ctl, $rtl);
1716 }
1717 } # cell
1718  
1719 70 1;
1720  
1721 70 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
1722 70 $INC{"Z10/Just/For/Testing.pm"} = $0;
1723 70 $INC{"Z20/Just/For/Testing.pm"} = $0;
1724 70 $Z10::Just::For::Testing::VERSION = "1.00";
1725 70 $Z20::Just::For::Testing::VERSION = undef;
1726 }
1727  
1728 package Z10::Just::For::Testing;
1729  
1730 70 1;
1731  
1732 package Z20::Just::For::Testing;
1733  
1734 70 1;
1735 __END__
↑ Summary