XLSX/Backend/LibXML.pm

filter: Statementstmt 93.8% 153 / 163 Branchbran 90.1% 101 / 112 Conditioncond 76.2% 45 / 59 MC/DCmcdc 54.5% 18 / 33 Subroutinesub 100% 18 / 18 Podpod n/a totaltotal 87.0% 335 / 385 CC 79 SCAR 31.8
CC
79
Cov
90%
__ANON__
49.6
_workbook_data
12.1
_date_styles
9.0
CRAP 24.1
↑ Summary XLSX/Backend/Regex.pm »
1 package Excel::ValueReader::XLSX::Backend::LibXML;
2 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use 5.12.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use XML::LibXML::Reader qw/XML_READER_TYPE_END_ELEMENT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Iterator::Simple qw/iter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 extends 'Excel::ValueReader::XLSX::Backend';
10  
11 #======================================================================
12 # LAZY ATTRIBUTE CONSTRUCTORS
13 #======================================================================
14  
15 8 ▶sub _strings {
Subroutine _strings: called CC=7 SCAR=19.5
16 8 my $self = shift;
17  
18 8 my $reader = $self->_xml_reader_for_zip_member('xl/sharedStrings.xml');
19  
20 8 my @strings;
21 my $last_string;
22 NODE:
23 8 ▶ while ($reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read) 2716 8 2724
24 2716 ▶ next NODE if $reader->nodeType == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->nodeType == 15 1080 1636 2716
25 1636 my $node_name = $reader->name;
26  
27 1636 ▶ if ($node_name eq 'si') {
Branch: 2 branches
BranchTrueFalseTotal
if ($node_name eq 'si') { } 530 1106 1636
elsif ($node_name eq '#text') { } 532 574 1106
28 530 ▶ push @strings, $last_string if defined $last_string;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_string 522 8 530
29 530 $last_string = '';
30 }
31 elsif ($node_name eq '#text') {
32 532 $last_string .= $reader->value;
33 }
34 }
35  
36 8 ▶ push @strings, $last_string if defined $last_string;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_string 8 0 8
37  
38 8 return \@strings;
39 }
40  
41  
42 15 ▶sub _workbook_data {
Subroutine _workbook_data: called CC=12 SCAR=24.9
43 15 my $self = shift;
44  
45 15 my %workbook_data = (sheets => {}, base_year => 1900);
46 15 my $sheet_id = 1;
47  
48 15 my $reader = $self->_xml_reader_for_zip_member('xl/workbook.xml');
49  
50 NODE:
51 15 ▶ while ($reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read) 469 15 484
52 469 ▶ next NODE if $reader->nodeType == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->nodeType == 15 119 350 469
53  
54 350 ▶ if ($reader->name eq 'sheet') {
Branch: 3 branches
BranchTrueFalseTotal
if ($reader->name eq 'sheet') { } 61 289 350
elsif ($reader->name eq 'workbookPr' and my $date_attr = $reader->getAttribute('date1904')) { } 4 285 289
elsif ($reader->name eq 'workbookView' and my $active_attr = $reader->getAttribute('activeTab')) { } 7 548 555
55 61 ▶ my $name = $reader->getAttribute('name')
Branch: 1 branch
BranchTrueFalseTotal
my $name = $reader->getAttribute("name") or die "sheet node without name" 61 0 61
56 or die "sheet node without name";
57 61 $workbook_data{sheets}{$name} = $sheet_id++;
58 }
59 ▶ elsif ($reader->name eq 'workbookPr' and my $date_attr = $reader->getAttribute('date1904')) {
Condition100%3/3
$reader->name eq "workbookPr" and my $date_attr = $reader->getAttribute("date1904")
!ll&&!rl&&r
274114
MC/DC100%2/2
$reader->name eq "workbookPr" and my $date_attr = $reader->getAttribute("date1904")
$reader->name eq "workbookPr" my $date_attr = $reader->getAttribute("date1904")
Truth table100%3/3
A and B
A= $reader->name eq "workbookPr"B= my $date_attr = $reader->getAttribute("date1904")
ABresult
0X0
100
111
60 4 ▶ $workbook_data{base_year} = 1904 if $date_attr eq '1' or $date_attr eq 'true'; # this workbook uses the 1904 calendar
Branch: 1 branch
BranchTrueFalseTotal
if $date_attr eq 1 or $date_attr eq "true" 2 2 4
Condition66%2/3
$date_attr eq 1 or $date_attr eq "true"
l!l&&r!l&&!r
202
MC/DC50%1/2
$date_attr eq 1 or $date_attr eq "true"
$date_attr eq 1 $date_attr eq "true"
Truth table66%2/3
A or B
A= $date_attr eq 1B= $date_attr eq "true"
ABresult
1X1
011
000
61 }
62 ▶ elsif ($reader->name eq 'workbookView' and my $active_attr = $reader->getAttribute('activeTab')) {
Condition100%3/3
$reader->name eq "workbookView" and my $active_attr = $reader->getAttribute("activeTab")
!ll&&!rl&&r
27087
MC/DC100%2/2
$reader->name eq "workbookView" and my $active_attr = $reader->getAttribute("activeTab")
$reader->name eq "workbookView" my $active_attr = $reader->getAttribute("activeTab")
Truth table100%3/3
A and B
A= $reader->name eq "workbookView"B= my $active_attr = $reader->getAttribute("activeTab")
ABresult
0X0
100
111
63 7 ▶ $workbook_data{active_sheet} = $active_attr + 1 if defined $active_attr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $active_attr 7 0 7
64 }
65 }
66  
67 15 return \%workbook_data;
68 }
69  
70  
71 10 ▶sub _date_styles {
Subroutine _date_styles: called CC=9 SCAR=22.0
72 10 my $self = shift;
73  
74 10 state $date_style_regex = qr{[dy]|\bmm\b};
75 10 my @date_styles;
76  
77 # read from the styles.xml zip member
78 10 my $xml_reader = $self->_xml_reader_for_zip_member('xl/styles.xml');
79  
80 # start with Excel builtin number formats for dates and times
81 10 my @numFmt = $self->Excel_builtin_date_formats;
82  
83 10 my $expected_subnode = undef;
84  
85 # add other date formats explicitly specified in this workbook
86 NODE:
87 10 ▶ while ($xml_reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->read) 1458 10 1468
88 1458 ▶ next NODE if $xml_reader->nodeType == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $xml_reader->nodeType == 15 340 1118 1458
89  
90 # special treatment for some specific subtrees -- see 'numFmt' and 'xf' below
91 1118 ▶ if ($expected_subnode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected_subnode) 386 732 1118
92 386 my ($name, $depth, $handler) = @$expected_subnode;
93 386 ▶ if ($xml_reader->name eq $name && $xml_reader->depth == $depth) {
Branch: 2 branches
BranchTrueFalseTotal
if ($xml_reader->name eq $name and $xml_reader->depth == $depth) { } 256 130 386
elsif ($xml_reader->depth < $depth) { } 18 112 130
Condition66%2/3
$xml_reader->name eq $name and $xml_reader->depth == $depth
!ll&&!rl&&r
1300256
MC/DC50%1/2
$xml_reader->name eq $name and $xml_reader->depth == $depth
$xml_reader->name eq $name $xml_reader->depth == $depth
Truth table66%2/3
A and B
A= $xml_reader->name eq $nameB= $xml_reader->depth == $depth
ABresult
0X0
100
111
94 # process that subnode and go to the next node
95 256 $handler->();
96 256 next NODE;
97 }
98 elsif ($xml_reader->depth < $depth) {
99 # finished handling subnodes; back to regular node treatment
100 18 $expected_subnode = undef;
101 }
102 }
103  
104 # regular node treatement
105 862 ▶ if ($xml_reader->name eq 'numFmts') {
Branch: 2 branches
BranchTrueFalseTotal
if ($xml_reader->name eq 'numFmts') { } 8 854 862
elsif ($xml_reader->name eq 'cellXfs') { } 10 844 854
106 # start parsing nodes for numeric formats
107 76 ▶ $expected_subnode = [numFmt => $xml_reader->depth+1 => sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
108 76 my $id = $xml_reader->getAttribute('numFmtId');
109 76 my $code = $xml_reader->getAttribute('formatCode');
110 76 ▶ $numFmt[$id] = $code if $id && $code && $code =~ $date_style_regex;
Branch: 1 branch
BranchTrueFalseTotal
if $id and $code and $code =~ /$date_style_regex/u 74 2 76
Condition50%3/6
$id and $code and $code =~ /$date_style_regex/u
!ll&&!rl&&r
0274
$id and $code
!ll&&!rl&&r
0076
MC/DC33%1/3
$id and $code and $code =~ /$date_style_regex/u
$id $code $code =~ /$date_style_regex/u
Truth table50%2/4
A and B and C
A= $idB= $codeC= $code =~ /$date_style_regex/u
ABCresult
0XX0
10X0
1100
1111
111 8 }];
112 }
113  
114 elsif ($xml_reader->name eq 'cellXfs') {
115 # start parsing nodes for cell formats
116 180 ▶ $expected_subnode = [xf => $xml_reader->depth+1 => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
117 180 state $xf_count = 0;
118 180 my $numFmtId = $xml_reader->getAttribute('numFmtId');
119 180 my $code = $numFmt[$numFmtId]; # may be undef
120 180 $date_styles[$xf_count++] = $code;
121 10 }];
122 }
123 }
124  
125 10 return \@date_styles;
126 }
127  
128  
129  
130 #======================================================================
131 # METHODS
132 #======================================================================
133  
134 99 ▶sub _xml_reader {
Subroutine _xml_reader: called CC=1 SCAR=0.0
135 99 my ($self, $xml) = @_;
136  
137 99 my $reader = XML::LibXML::Reader->new(string => $xml,
138 no_blanks => 1,
139 no_network => 1,
140 huge => 1);
141 99 return $reader;
142 }
143  
144  
145 77 ▶sub _xml_reader_for_zip_member {
Subroutine _xml_reader_for_zip_member: called CC=1 SCAR=0.0
146 77 my ($self, $member_name) = @_;
147  
148 77 my $contents = $self->_zip_member_contents($member_name);
149 77 return $self->_xml_reader($contents);
150 }
151  
152  
153 44 ▶sub _values {
Subroutine _values: called CC=4 SCAR=14.1
154 44 my ($self, $sheet, $want_iterator) = @_;
155  
156 # prepare for traversing the XML structure
157 44 my $has_date_formatter = $self->frontend->date_formatter;
158 44 my $sheet_member_name = $self->_zip_member_name_for_sheet($sheet);
159 44 my $xml_reader = $self->_xml_reader_for_zip_member($sheet_member_name);
160  
161  
162 # get sheet 'ref' attribute from the initial preamble
163 44 my $ref;
164 PREAMBLE:
165 44 ▶ while ($xml_reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->read) 100 0 100
166 100 ▶ if ($xml_reader->name eq 'dimension') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->name eq "dimension") 44 56 100
167 44 $ref = $xml_reader->getAttribute('ref');
168 44 last PREAMBLE;
169 }
170 }
171  
172  
173  
174 44 my ($row_num, $col_num, @rows) = (0, 0);
175 44 my ($cell_type, $cell_style, $seen_node);
176  
177 # dual closure : may be used as an iterator or as a regular sub, depending on $want_iterator. Of course
178 # it would have been simpler to just write an iterator, and call it in a loop if the client wants all rows
179 # at once ... but thousands of additional sub calls would slow down the process. So this more complex implementation
180 # is for the sake of processing speed.
181 2100066 ▶ my $get_values = sub {
Subroutine __ANON__: called CC=39 SCAR=39.0
182  
183 # in iterator mode, if we have a row ready, just return it
184 2100066 ▶ return shift @rows if $want_iterator and @rows > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $want_iterator and @rows > 1 2099210 856 2100066
Condition100%3/3
$want_iterator and @rows > 1
!ll&&!rl&&r
228342099210
MC/DC100%2/2
$want_iterator and @rows > 1
$want_iterator @rows > 1
Truth table100%3/3
A and B
A= $want_iteratorB= @rows > 1
ABresult
0X0
100
111
185  
186 # otherwise loop on matching nodes
187 NODE:
188 856 ▶ while ($xml_reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->read) 22244 13 22257
189 22244 my $node_name = $xml_reader->name;
190 22244 my $node_type = $xml_reader->nodeType;
191  
192 22244 ▶ $xml_reader->finish and last NODE if $node_name eq 'sheetData' && $node_type == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $node_name eq "sheetData" and $node_type == 15 35 22209 22244
Condition75%6/8
$node_name eq 'sheetData' && $node_type == 15 && ($xml_reader->finish && (last NODE))
!ll&&!rl&&r
22209350
$node_name eq "sheetData" and $node_type == 15
!ll&&!rl&&r
221654435
$xml_reader->finish and last NODE
!ll
035
MC/DC0%0/3
$node_name eq 'sheetData' && $node_type == 15 && ($xml_reader->finish && (last NODE))
$node_name eq "sheetData" $node_type == 15 $xml_reader->finish
Truth table50%2/4
A and B && C
A= $node_name eq "sheetData"B= $node_type == 15C= $xml_reader->finish
ABCresult
0XX0
10X0
1100
1111
193 22209 ▶ next NODE if $node_type == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $node_type == 15 9031 13178 22209
194  
195 13178 ▶ if ($node_name eq 'row') {
Branch: 4 branches
BranchTrueFalseTotal
if ($node_name eq 'row') { } 1746 11432 13178
elsif ($node_name eq 'c') { } 3880 7552 11432
elsif ($node_name =~ /^[vtf]$/u) { } 3608 3944 7552
elsif ($node_name eq '#text') { } 3608 336 3944
196 1746 my $prev_row = $row_num;
197 1746 ▶ $row_num = $xml_reader->getAttribute('r') // $row_num+1;
Condition100%2/2
$xml_reader->getAttribute("r") // $row_num + 1
l!l
17442
MC/DC100%1/1
$xml_reader->getAttribute("r") // $row_num + 1
$xml_reader->getAttribute("r")
Truth table100%2/2
A
A= $xml_reader->getAttribute("r")
Aresult
11
00
198 1746 $col_num = 0;
199 1746 push @rows, [] for 1 .. $row_num-$prev_row;
200  
201 # in iterator mode, if we have a closed empty row, just return it
202 1746 ▶ return shift @rows if $want_iterator and @rows > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $want_iterator and @rows > 1 808 938 1746
Condition100%3/3
$want_iterator and @rows > 1
!ll&&!rl&&r
91820808
MC/DC100%2/2
$want_iterator and @rows > 1
$want_iterator @rows > 1
Truth table100%3/3
A and B
A= $want_iteratorB= @rows > 1
ABresult
0X0
100
111
203 }
204  
205 elsif ($node_name eq 'c') {
206 3880 ▶ my $A1_cell_ref = $xml_reader->getAttribute('r') // '';
Condition100%2/2
$xml_reader->getAttribute("r") // ""
l!l
385624
MC/DC100%1/1
$xml_reader->getAttribute("r") // ""
$xml_reader->getAttribute("r")
Truth table100%2/2
A
A= $xml_reader->getAttribute("r")
Aresult
11
00
207 3880 my ($col_A1, $given_row) = ($A1_cell_ref =~ /^([A-Z]+)(\d+)$/);
208  
209 3880 ▶ $given_row //= $row_num;
Condition66%2/3
$given_row //= $row_num
l!l&&r!l&&!r
3856240
MC/DC0%0/2
$given_row //= $row_num
$given_row $row_num
Truth table66%2/3
A //= B
A= $given_rowB= $row_num
ABresult
1X1
011
000
210 0 ▶ if ($given_row < $row_num) {die "cell claims to be in row $given_row while current row is $row_num"}
Branch: 2 branches
BranchTrueFalseTotal
if ($given_row < $row_num) { } 0 3880 3880
elsif ($given_row > $row_num) { } 0 3880 3880
211 0 elsif ($given_row > $row_num) {push @rows, [] for 1 .. $given_row-$row_num;
212 0 $col_num = 0;
213 0 $row_num = $given_row;}
214  
215 # deal with the col number given in the 'r' attribute, if present
216 3880 ▶ if ($col_A1) {$col_num = $Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1}
Branch: 1 branch
BranchTrueFalseTotal
if ($col_A1) { } 3856 24 3880
Condition33%1/3
$Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1} //= "Excel::ValueReader::XLSX"->A1_to_num($col_A1)
l!l&&r!l&&!r
385600
MC/DC0%0/2
$Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1} //= "Excel::ValueReader::XLSX"->A1_to_num($col_A1)
$Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1} "Excel::ValueReader::XLSX"->A1_to_num($col_A1)
Truth table33%1/3
A //= B
A= $Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1}B= "Excel::ValueReader::XLSX"->A1_to_num($col_A1)
ABresult
1X1
011
000
217 //= Excel::ValueReader::XLSX->A1_to_num($col_A1)}
218 24 else {$col_num++}
219  
220 3880 $cell_type = $xml_reader->getAttribute('t');
221 3880 $cell_style = $xml_reader->getAttribute('s');
222 3880 $seen_node = '';
223 }
224  
225 elsif ($node_name =~ /^[vtf]$/) {
226 # remember that we have seen a 'value' or 'text' or 'formula' node
227 3608 $seen_node = $node_name;
228 }
229  
230 elsif ($node_name eq '#text') {
231 #start processing cell content
232  
233 3608 my $val = $xml_reader->value;
234 3608 ▶ $cell_type //= '';
Condition100%2/2
$cell_type //= ""
l!l
24891119
MC/DC100%1/1
$cell_type //= ""
$cell_type
Truth table100%2/2
A
A= $cell_type
Aresult
11
00
235  
236 3608 ▶ if ($seen_node eq 'v') {
Branch: 3 branches
BranchTrueFalseTotal
if ($seen_node eq 'v') { } 3578 30 3608
elsif ($seen_node eq 't' and $cell_type eq 'inlineStr') { } 0 30 30
elsif ($seen_node eq 'f') { } 30 0 30
237 3578 ▶ if ($cell_type eq 's') {
Branch: 3 branches
BranchTrueFalseTotal
if ($cell_type eq 's') { } 2433 1145 3578
elsif ($cell_type eq 'e') { } 0 1145 1145
elsif ($cell_type =~ /^(n|d|b|str|)$/u) { } 1145 0 1145
238 2433 ▶ if (looks_like_number($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($val)) { } 2433 0 2433
239 2433 $val = $self->strings->[$val]; # string -- pointer into the global array of shared strings
240 }
241 else {
242 0 warn "unexpected non-numerical value: $val inside a node of shape <v t='s'>\n";
243 }
244 }
245 elsif ($cell_type eq 'e') {
246 0 $val = undef; # error -- silently replace by undef
247 }
248 elsif ($cell_type =~ /^(n|d|b|str|)$/) {
249 # number, date, boolean, formula string or no type : content is already in $val
250  
251 # if this is a date, replace the numeric value by the formatted date
252 1145 ▶ if ($has_date_formatter && $cell_style && looks_like_number($val) && $val >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_date_formatter and $cell_style and &looks_like_number($val) and $val >= 0) 486 659 1145
Condition88%8/9
$has_date_formatter and $cell_style and &looks_like_number($val) and $val >= 0
!ll&&!rl&&r
6590486
$has_date_formatter and $cell_style and &looks_like_number($val)
!ll&&!rl&&r
6572486
$has_date_formatter and $cell_style
!ll&&!rl&&r
52605488
MC/DC75%3/4
$has_date_formatter and $cell_style and &looks_like_number($val) and $val >= 0
$has_date_formatter $cell_style &looks_like_number($val) $val >= 0
Truth table80%4/5
A and B and C and D
A= $has_date_formatterB= $cell_styleC= &looks_like_number($val)D= $val >= 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
253 486 my $date_style = $self->date_styles->[$cell_style];
254 486 ▶ $val = $self->formatted_date($val, $date_style) if $date_style;
Branch: 1 branch
BranchTrueFalseTotal
if $date_style 152 334 486
255 }
256 }
257 else {
258 # handle unexpected cases
259 0 warn "unsupported type '$cell_type' in cell L${row_num}C${col_num}\n";
260 0 $val = undef;
261 }
262  
263 # insert this value into the last row
264 3578 $rows[-1][$col_num-1] = $val;
265 }
266  
267 ▶ elsif ($seen_node eq 't' && $cell_type eq 'inlineStr') {
Condition33%1/3
$seen_node eq "t" and $cell_type eq "inlineStr"
!ll&&!rl&&r
3000
MC/DC0%0/2
$seen_node eq "t" and $cell_type eq "inlineStr"
$seen_node eq "t" $cell_type eq "inlineStr"
Truth table33%1/3
A and B
A= $seen_node eq "t"B= $cell_type eq "inlineStr"
ABresult
0X0
100
111
268 # inline string -- accumulate all #text nodes until next cell
269 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
270 0 $rows[-1][$col_num-1] .= $val;
271 }
272  
273 elsif ($seen_node eq 'f') {
274 # formula -- just ignore it
275 }
276  
277 else {
278 # handle unexpected cases
279 0 warn "unexpected text node in cell L${row_num}C${col_num}: $val\n";
280 }
281 }
282 }
283  
284 # end of XML nodes. In iterator mode, return a row if we have one
285 48 ▶ return @rows ? shift @rows : undef if $want_iterator;
Branch: 2 branches
BranchTrueFalseTotal
if $want_iterator 26 22 48
@rows ? : 14 12 26
286 44 };
287  
288 # decide what to return depending on the dual mode
289 my $retval = $want_iterator ? iter($get_values)
290 44 ▶ : do {$get_values->(); \@rows}; # run the closure and return the rows
Branch: 1 branch
BranchTrueFalseTotal
$want_iterator ? : 22 22 44
291  
292 44 return ($ref, $retval);
293 }
294  
295  
296  
297  
298 10 ▶sub _table_targets {
Subroutine _table_targets: called CC=5 SCAR=16.1
299 10 my ($self, $rel_xml) = @_;
300  
301 10 my $xml_reader = $self->_xml_reader($rel_xml);
302  
303 10 my @table_targets;
304  
305 # iterate through XML nodes
306 NODE:
307 10 ▶ while ($xml_reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->read) 38 10 48
308 38 my $node_name = $xml_reader->name;
309 38 my $node_type = $xml_reader->nodeType;
310 38 ▶ next NODE if $node_type == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $node_type == 15 10 28 38
311  
312 28 ▶ if ($node_name eq 'Relationship') {
Branch: 1 branch
BranchTrueFalseTotal
if ($node_name eq "Relationship") 18 10 28
313 18 my $target = $xml_reader->getAttribute('Target');
314 18 ▶ if ($target =~ m[tables/table(\d+)\.xml]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ m[tables/table(\d+)\.xml]u) 12 6 18
315 # just store the table id (positive integer)
316 12 push @table_targets, $1;
317 }
318 }
319 }
320  
321 10 return @table_targets;
322 }
323  
324  
325 12 ▶sub _parse_table_xml {
Subroutine _parse_table_xml: called CC=6 SCAR=17.9
326 12 my ($self, $xml) = @_;
327  
328 12 my %table_info;
329  
330 12 my $xml_reader = $self->_xml_reader($xml);
331  
332 # iterate through XML nodes
333 NODE:
334 12 ▶ while ($xml_reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml_reader->read) 108 12 120
335 108 my $node_name = $xml_reader->name;
336 108 my $node_type = $xml_reader->nodeType;
337 108 ▶ next NODE if $node_type == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $node_type == 15 24 84 108
338  
339 84 ▶ if ($node_name eq 'table') {
Branch: 2 branches
BranchTrueFalseTotal
if ($node_name eq 'table') { } 12 72 84
elsif ($node_name eq 'tableColumn') { } 38 34 72
340 %table_info = (
341 name => $xml_reader->getAttribute('displayName'),
342 ref => $xml_reader->getAttribute('ref'),
343 12 no_headers => do {my $has_headers = $xml_reader->getAttribute('headerRowCount');
344 12 ▶ defined $has_headers && !$has_headers},
Condition66%2/3
defined $has_headers && !$has_headers
!ll&&!rl&&r
1002
MC/DC50%1/2
defined $has_headers && !$has_headers
defined $has_headers !$has_headers
Truth table66%2/3
A && not(B)
A= defined $has_headersB= !$has_headers
ABresult
0X0
100
111
345 has_totals => $xml_reader->getAttribute('totalsRowCount'),
346 );
347 }
348 elsif ($node_name eq 'tableColumn') {
349 38 push @{$table_info{columns}}, $xml_reader->getAttribute('name');
350 }
351 }
352  
353 12 return \%table_info
354 }
355  
356  
357  
358  
359 2 1;
360  
361  
362 __END__
↑ Summary XLSX/Backend/Regex.pm »