| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2716 | ▶ | next NODE if $reader->nodeType == XML_READER_TYPE_END_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1636 | my $node_name = $reader->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1636 | ▶ | if ($node_name eq 'si') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 530 | ▶ | push @strings, $last_string if defined $last_string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 469 | ▶ | next NODE if $reader->nodeType == XML_READER_TYPE_END_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 350 | ▶ | if ($reader->name eq 'sheet') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 61 | ▶ | my $name = $reader->getAttribute('name') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$date_attr eq 1 or $date_attr eq "true"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | ▶ | $workbook_data{active_sheet} = $active_attr + 1 if defined $active_attr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1458 | ▶ | next NODE if $xml_reader->nodeType == XML_READER_TYPE_END_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # special treatment for some specific subtrees -- see 'numFmt' and 'xf' below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1118 | ▶ | if ($expected_subnode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 386 | my ($name, $depth, $handler) = @$expected_subnode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 386 | ▶ | if ($xml_reader->name eq $name && $xml_reader->depth == $depth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$xml_reader->name eq $name and $xml_reader->depth == $depth
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$id and $code and $code =~ /$date_style_regex/u
$id and $code
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 100 | ▶ | if ($xml_reader->name eq 'dimension') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$want_iterator and @rows > 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # otherwise loop on matching nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | NODE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 856 | ▶ | while ($xml_reader->read) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition75%6/8
$node_name eq 'sheetData' && $node_type == 15 && ($xml_reader->finish && (last NODE))
$node_name eq "sheetData" and $node_type == 15
$xml_reader->finish and last NODE
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 22209 | ▶ | next NODE if $node_type == XML_READER_TYPE_END_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 13178 | ▶ | if ($node_name eq 'row') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$want_iterator and @rows > 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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") // ""
MC/DC100%1/1
$xml_reader->getAttribute("r") // ""
$xml_reader->getAttribute("r")
Truth table100%2/2
A
A= $xml_reader->getAttribute("r")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$given_row //= $row_num
$given_row
$row_num
Truth table66%2/3
A //= B
A= $given_rowB= $row_num
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1} //= "Excel::ValueReader::XLSX"->A1_to_num($col_A1)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 //= ""
MC/DC100%1/1
$cell_type //= ""
$cell_type
Truth table100%2/2
A
A= $cell_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3608 | ▶ | if ($seen_node eq 'v') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 3578 | ▶ | if ($cell_type eq 's') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2433 | ▶ | if (looks_like_number($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition88%8/9
$has_date_formatter and $cell_style and &looks_like_number($val) and $val >= 0
$has_date_formatter and $cell_style and &looks_like_number($val)
$has_date_formatter and $cell_style
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 28 | ▶ | if ($node_name eq 'Relationship') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 18 | my $target = $xml_reader->getAttribute('Target'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 18 | ▶ | if ($target =~ m[tables/table(\d+)\.xml]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 84 | ▶ | if ($node_name eq 'table') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||