OOXML/Part/WordprocessingML.pm

filter: Statementstmt 95.5% 214 / 224 Branchbran 77.5% 62 / 80 Conditioncond 45.8% 22 / 48 MC/DCmcdc 20.0% 6 / 30 Subroutinesub 100% 29 / 29 Podpod 77.7% 7 / 9 totaltotal 80.9% 340 / 420 CC 65 SCAR 29.1
CC
65
Cov
85%
style_text
50.2
__ANON__
10.1
__ANON__
6.1
CRAP 18.4
↑ Summary OOXML.pm »
1 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Document::OOXML::Part::WordprocessingML;
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 with 'Document::OOXML::Part';
7  
8 # ABSTRACT: WordprocessingML document part handling
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 2 has xml => (
16 is => 'ro',
17 isa => 'XML::LibXML::Document',
18 required => 1,
19 );
20  
21  
22 2 has xpc => (
23 is => 'ro',
24 isa => 'XML::LibXML::XPathContext',
25 required => 1,
26 );
27  
28 2 has is_strict => (
29 is => 'ro',
30 isa => 'Bool',
31 required => 1,
32 );
33  
34 9 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
35 9 my $self = shift;
36 9 return $self->xml->toString();
37 }
38  
39 2 my %XML_NS = (
40 strict => 'http://purl.oclc.org/ooxml/wordprocessingml/main',
41 transitional => 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
42  
43 relationships_strict => 'http://purl.oclc.org/ooxml/officeDocument/relationships',
44 relationships => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
45 );
46  
47  
48 25 ▶sub new_from_xml {
Subroutine new_from_xml: called CC=2 SCAR=6.9
Pod documented
49 25 my $class = shift;
50 25 my $part_name = shift;
51 25 my $xml = shift;
52 25 my $is_strict = shift;
53  
54 25 my $doc = XML::LibXML->load_xml( string => $xml );
55 25 my $xpc = XML::LibXML::XPathContext->new();
56  
57 25 ▶ if ($is_strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_strict) { } 16 9 25
58 16 $xpc->registerNs('w' => $XML_NS{strict});
59 16 $xpc->registerNs('r' => $XML_NS{relationships_strict});
60 } else {
61 9 $xpc->registerNs('w' => $XML_NS{transitional});
62 9 $xpc->registerNs('r' => $XML_NS{relationships});
63 }
64  
65 25 return $class->new(
66 part_name => $part_name,
67 xml => $doc,
68 xpc => $xpc,
69 is_strict => $is_strict,
70 );
71 }
72  
73 57 ▶sub _clone_run {
Subroutine _clone_run: called CC=2 SCAR=6.9
74 57 my $self = shift;
75 57 my $run = shift;
76  
77 57 my $new_run = $run->cloneNode(0);
78  
79 57 my ($run_props) = $self->xpc->findnodes('./w:rPr', $run);
80 57 ▶ if ($run_props) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run_props) 33 24 57
81 33 my $new_props = $run_props->cloneNode(1);
82 33 $new_run->appendChild($new_props);
83 }
84  
85 57 return $new_run;
86 }
87  
88  
89 23 ▶sub find_text_nodes {
Subroutine find_text_nodes: called CC=3 SCAR=11.0
Pod documented
90 23 my $self = shift;
91 23 my $regex = shift;
92 23 my $exclude_tables = shift;
93  
94 23 ▶ my $text_element_query = $exclude_tables
Branch: 1 branch
BranchTrueFalseTotal
$exclude_tables ? : 0 23 23
95 ? '//w:r[child::w:t and not(ancestor::w:tbl)]'
96 : '//w:r[child::w:t]';
97  
98 23 my @matching_nodes;
99  
100 # Find all text nodes matching $regex that are not in a table
101 23 my $runs = $self->xpc->findnodes($text_element_query, $self->xml->documentElement);
102 70 ▶ $runs->foreach(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
103 70 my $run = shift;
104  
105 70 my $run_was_split = 0;
106  
107 70 my $text_nodes = $self->xpc->findnodes('./w:t', $run);
108 70 ▶ $text_nodes->foreach(sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
109 70 my $t = shift;
110 70 my $run = $t->parentNode;
111  
112 70 my @parts = split(/($regex)/, $t->textContent);
113  
114 # No match, no need to do all the DOM processing below
115 70 ▶ return if @parts == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 47 23 70
116  
117 23 $run_was_split = 1;
118  
119 23 ▶ for (my $i = $#parts; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 67 23 90
120 67 my $part = $parts[$i];
121 67 ▶ next if $part eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $part eq "" 10 57 67
122  
123 57 my $new_run = $self->_clone_run($run);
124 57 my $new_text = $t->cloneNode(0);
125  
126 # Ensure leading/trailing whitespace is preserved
127 57 $new_text->setAttributeNS(XML_XML_NS, 'xml:space', 'preserve');
128  
129 57 $new_text->appendText($part);
130 57 $new_text->normalize();
131 57 $new_run->appendChild($new_text);
132  
133 57 $run->parentNode->insertAfter($new_run, $run);
134  
135 57 ▶ if ($i % 2 != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2 != 0) 27 30 57
136 27 push @matching_nodes, $new_text->childNodes;
137 }
138 }
139 70 });
140  
141 70 ▶ $run->parentNode->removeChild($run) if $run_was_split;
Branch: 1 branch
BranchTrueFalseTotal
if $run_was_split 23 47 70
142 23 });
143  
144 23 for my $part ($self->referenced_parts) {
145 12 my $nodes = $part->find_text_nodes(
146 $regex,
147 $exclude_tables,
148 );
149  
150 12 push @matching_nodes, @$nodes;
151 }
152  
153 23 return \@matching_nodes;
154 }
155  
156  
157 6 ▶sub style_text {
Subroutine style_text: called CC=29 SCAR=39.2
Pod documented
158 6 my $self = shift;
159 6 my $regex = shift;
160 6 my %options = @_;
161  
162 6 my $text_nodes = $self->find_text_nodes($regex, delete $options{exclude_tables});
163  
164 6 for my $text_node (@$text_nodes) {
165 8 my ($run_props) = $self->xpc->findnodes('ancestor::w:r[1]/w:rPr', $text_node);
166 8 ▶ if (!$run_props) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($run_props) 7 1 8
167 7 my ($run) = $self->xpc->findnodes('ancestor::w:r[1]', $text_node);
168  
169 7 my $run_ns = $run->namespaceURI;
170 7 $run_props = $self->xml->createElement('rPr');
171 7 $run_props->setNamespace($run_ns => $run->lookupNamespacePrefix($run_ns));
172 7 $run->insertBefore($run_props, $run->firstChild);
173 }
174  
175 8 ▶ if (exists $options{bold}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"bold"}) 3 5 8
176 3 my ($bold) = $self->xpc->findnodes('./w:b', $run_props);
177  
178 3 ▶ if (!$bold && $options{bold}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $bold and $options{"bold"}) 3 0 3
Condition33%1/3
not $bold and $options{"bold"}
!ll&&!rl&&r
003
MC/DC0%0/2
not $bold and $options{"bold"}
not $bold $options{"bold"}
Truth table33%1/3
not(A) and B
A= not $boldB= $options{"bold"}
ABresult
0X0
100
111
179 3 $run_props->addNewChild($run_props->namespaceURI => 'b');
180 }
181 3 ▶ if ($bold && !$options{bold}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bold and not $options{"bold"}) 0 3 3
Condition33%1/3
$bold and not $options{"bold"}
!ll&&!rl&&r
300
MC/DC0%0/2
$bold and not $options{"bold"}
$bold not $options{"bold"}
Truth table33%1/3
A and not(B)
A= $boldB= not $options{"bold"}
ABresult
0X0
100
111
182 0 $run_props->removeChild($bold);
183 }
184 }
185  
186 8 ▶ if (exists $options{italic}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"italic"}) 1 7 8
187 1 my ($italic) = $self->xpc->findnodes('./w:i', $run_props);
188  
189 1 ▶ if (!$italic && $options{italic}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $italic and $options{"italic"}) 1 0 1
Condition33%1/3
not $italic and $options{"italic"}
!ll&&!rl&&r
001
MC/DC0%0/2
not $italic and $options{"italic"}
not $italic $options{"italic"}
Truth table33%1/3
not(A) and B
A= not $italicB= $options{"italic"}
ABresult
0X0
100
111
190 1 $run_props->addNewChild($run_props->namespaceURI => 'i');
191 }
192 1 ▶ if ($italic && !$options{italic}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($italic and not $options{"italic"}) 0 1 1
Condition33%1/3
$italic and not $options{"italic"}
!ll&&!rl&&r
100
MC/DC0%0/2
$italic and not $options{"italic"}
$italic not $options{"italic"}
Truth table33%1/3
A and not(B)
A= $italicB= not $options{"italic"}
ABresult
0X0
100
111
193 0 $run_props->removeChild($italic);
194 }
195 }
196  
197 8 ▶ if (exists $options{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"color"}) 2 6 8
198 2 my $color_to_set = _check_color_syntax($options{color});
199  
200 2 my ($color_element) = $self->xpc->findnodes('./w:color', $run_props);
201  
202 2 ▶ if (!$color_element && $options{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $color_element and $options{"color"}) 1 1 2
Condition66%2/3
not $color_element and $options{"color"}
!ll&&!rl&&r
101
MC/DC50%1/2
not $color_element and $options{"color"}
not $color_element $options{"color"}
Truth table66%2/3
not(A) and B
A= not $color_elementB= $options{"color"}
ABresult
0X0
100
111
203 1 $color_element = $run_props->addNewChild($run_props->namespaceURI => 'color');
204 }
205  
206 2 ▶ if ($color_element && $options{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color_element and $options{"color"}) 2 0 2
Condition33%1/3
$color_element and $options{"color"}
!ll&&!rl&&r
002
MC/DC0%0/2
$color_element and $options{"color"}
$color_element $options{"color"}
Truth table33%1/3
A and B
A= $color_elementB= $options{"color"}
ABresult
0X0
100
111
207 2 my $ns = $color_element->namespaceURI;
208  
209 2 $color_element->setAttributeNS(
210 $ns,
211 'val' => $color_to_set
212 );
213  
214 # We're explicitly setting the color, so we need to remove
215 # the "document theme"-based color attributes or they'll
216 # take precedence.
217 2 $color_element->removeAttributeNS($ns => 'themeColor');
218 2 $color_element->removeAttributeNS($ns => 'themeShade');
219 2 $color_element->removeAttributeNS($ns => 'themeTint');
220 }
221  
222 2 ▶ if ($color_element && not defined $options{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color_element and not defined $options{"color"}) 0 2 2
Condition33%1/3
$color_element and not defined $options{"color"}
!ll&&!rl&&r
020
MC/DC0%0/2
$color_element and not defined $options{"color"}
$color_element not defined $options{"color"}
Truth table33%1/3
A and not(B)
A= $color_elementB= not defined $options{"color"}
ABresult
0X0
100
111
223 0 $run_props->removeChild($color_element);
224 }
225 }
226  
227 8 ▶ if (exists $options{underline_style}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"underline_style"}) 2 6 8
228 2 my $underline_style = _check_underline_style($options{underline_style});
229  
230 2 my ($underline_element) = $self->xpc->findnodes('./w:u', $run_props);
231  
232 2 ▶ if (!$underline_element && $options{underline_style}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $underline_element and $options{"underline_style"}) 2 0 2
Condition33%1/3
not $underline_element and $options{"underline_style"}
!ll&&!rl&&r
002
MC/DC0%0/2
not $underline_element and $options{"underline_style"}
not $underline_element $options{"underline_style"}
Truth table33%1/3
not(A) and B
A= not $underline_elementB= $options{"underline_style"}
ABresult
0X0
100
111
233 2 $underline_element = $run_props->addNewChild($run_props->namespaceURI => 'u');
234 }
235  
236 2 ▶ if ($underline_element && $options{underline_style}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($underline_element and $options{"underline_style"}) 2 0 2
Condition33%1/3
$underline_element and $options{"underline_style"}
!ll&&!rl&&r
002
MC/DC0%0/2
$underline_element and $options{"underline_style"}
$underline_element $options{"underline_style"}
Truth table33%1/3
A and B
A= $underline_elementB= $options{"underline_style"}
ABresult
0X0
100
111
237 $underline_element->setAttributeNS(
238 $underline_element->namespaceURI,
239 'val' => $options{underline_style}
240 2 );
241  
242 2 ▶ if (exists $options{underline_color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"underline_color"}) 1 1 2
243 1 ▶ if (defined $options{underline_color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{'underline_color'}) { } 1 0 1
244 1 my $color_to_set = _check_color_syntax($options{underline_color});
245  
246 1 $underline_element->setAttributeNS(
247 $underline_element->namespaceURI,
248 'color' => $color_to_set,
249 );
250 } else {
251 0 $underline_element->removeAttributeNS(
252 $underline_element->namespaceURI => 'color'
253 );
254 }
255 }
256 }
257  
258 2 ▶ if ($underline_element && not defined $options{underline_style}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($underline_element and not defined $options{"underline_style"}) 0 2 2
Condition33%1/3
$underline_element and not defined $options{"underline_style"}
!ll&&!rl&&r
020
MC/DC0%0/2
$underline_element and not defined $options{"underline_style"}
$underline_element not defined $options{"underline_style"}
Truth table33%1/3
A and not(B)
A= $underline_elementB= not defined $options{"underline_style"}
ABresult
0X0
100
111
259 0 $run_props->removeChild($underline_element);
260 }
261 }
262 }
263  
264 6 return scalar @$text_nodes;
265 }
266  
267 3 ▶sub _check_color_syntax {
Subroutine _check_color_syntax: called CC=4 SCAR=15.6
268 3 my $color = shift;
269  
270 3 ▶ return if not defined $color;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color 0 3 3
271 3 ▶ return $color if $color eq 'auto';
Branch: 1 branch
BranchTrueFalseTotal
if $color eq "auto" 0 3 3
272 3 ▶ return uc($color) if $color =~ /^[0-9a-fA-F]{6}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $color =~ /^[0-9a-fA-F]{6}$/ 3 0 3
273  
274 0 croak("Invalid color value: '$color'");
275 }
276  
277 my %underline_styles = (
278 2 map { $_ => 1 } qw(
279 dash
280 dashDotDotHeavy
281 dashDotHeavy
282 dashedHeavy
283 dashLong
284 dashLongHeavy
285 dotDash
286 dotDotDash
287 dotted
288 dottedHeavy
289 double
290 none
291 single
292 thick
293 wave
294 wavyDouble
295 wavyHeavy
296 words
297 )
298 );
299  
300 2 ▶sub _check_underline_style {
Subroutine _check_underline_style: called CC=3 SCAR=12.5
301 2 my $underline_style = shift;
302  
303  
304 2 ▶ return if not defined $underline_style;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $underline_style 0 2 2
305 2 ▶ return $underline_style if exists $underline_styles{$underline_style};
Branch: 1 branch
BranchTrueFalseTotal
if exists $underline_styles{$underline_style} 2 0 2
306  
307 0 croak("Invalid underline style: '$underline_style'");
308 }
309  
310  
311 1 ▶sub remove_spellcheck_markers {
Subroutine remove_spellcheck_markers: called CC=2 SCAR=7.0
Pod documented
312 1 my $self = shift;
313  
314 1 my $spellcheck_nodes = $self->xpc->findnodes(
315 '//w:proofErr',
316 $self->xml->documentElement,
317 );
318 8 ▶ $spellcheck_nodes->foreach(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
319 8 my $node = shift;
320 8 $node->parentNode->removeChild($node);
321 1 });
322  
323 1 for my $part ($self->referenced_parts) {
324 0 $part->remove_spellcheck_markers();
325 }
326  
327 1 return;
328 }
329  
330  
331 8 ▶sub extract_words {
Subroutine extract_words: called CC=2 SCAR=6.9
Pod documented
332 8 my $self = shift;
333  
334 8 my @words;
335 8 my $text_nodes = $self->xpc->findnodes(
336 '//w:t',
337 $self->xml->documentElement,
338 );
339  
340 8 ▶ $text_nodes->foreach(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
341 8 my $node = shift;
342  
343 # split on non-word characters
344 8 push @words, grep { !/^\s*$/ } split(/[\W]+/, $node->textContent);
345 8 });
346  
347 8 for my $part ($self->referenced_parts) {
348 6 push @words, @{ $part->extract_words() };
349 }
350  
351 8 return \@words;
352 }
353  
354  
355 10 ▶sub merge_runs {
Subroutine merge_runs: called CC=2 SCAR=7.0
Pod documented
356 10 my $self = shift;
357  
358 10 my $runs = $self->xpc->findnodes(
359 '//w:p/w:r',
360 $self->xml->documentElement,
361 );
362  
363 10 my $active_run;
364 my $active_run_last_child;
365 10 my $active_run_props;
366 31 ▶ $runs->foreach(sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
367 31 my $run = shift;
368  
369 # If there's no "active" run, or the current run is in a new paragraph,
370 # start a new "active" run.
371 31 ▶ if ( !defined $active_run
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $active_run and $run->parentNode->isSameNode($active_run->parentNode)) 14 17 31
Condition100%3/3
defined $active_run and $run->parentNode->isSameNode($active_run->parentNode)
!ll&&!rl&&r
10417
MC/DC100%2/2
defined $active_run and $run->parentNode->isSameNode($active_run->parentNode)
defined $active_run $run->parentNode->isSameNode($active_run->parentNode)
Truth table100%3/3
A and B
A= defined $active_runB= $run->parentNode->isSameNode($active_run->parentNode)
ABresult
0X0
100
111
372 || !$run->parentNode->isSameNode($active_run->parentNode)
373 ) {
374 14 undef $active_run;
375 14 undef $active_run_last_child;
376 14 undef $active_run_props;
377 }
378  
379 31 my ($this_run_props) = $self->xpc->findnodes('./w:rPr', $run);
380  
381 31 ▶ $this_run_props = defined $this_run_props
Branch: 1 branch
BranchTrueFalseTotal
defined $this_run_props ? : 19 12 31
382 ? $this_run_props->toString
383 : '';
384  
385 # If properties match, merge all non-"run properties" child nodes
386 # into the active run. Then discard the (now empty) run.
387 31 ▶ if ( defined $active_run_props
Branch: 1 branch
BranchTrueFalseTotal
if (defined $active_run_props and $this_run_props eq $active_run_props) { } 13 18 31
Condition100%3/3
defined $active_run_props and $this_run_props eq $active_run_props
!ll&&!rl&&r
14413
MC/DC100%2/2
defined $active_run_props and $this_run_props eq $active_run_props
defined $active_run_props $this_run_props eq $active_run_props
Truth table100%3/3
A and B
A= defined $active_run_propsB= $this_run_props eq $active_run_props
ABresult
0X0
100
111
388 && $this_run_props eq $active_run_props
389 ) {
390 13 my $children = $run->childNodes;
391 23 ▶ $children->foreach(sub {
Subroutine __ANON__: called CC=8 SCAR=23.2
392 23 my $node = shift;
393 23 ▶ return if $node->nodeName eq 'w:rPr';
Branch: 1 branch
BranchTrueFalseTotal
if $node->nodeName eq "w:rPr" 7 16 23
394  
395 # If both the current child node and the last thing added to
396 # the active run are text nodes, merge contents instead of
397 # adding two adjacent <w:t> elements.
398 16 ▶ if ( $active_run_last_child
Branch: 1 branch
BranchTrueFalseTotal
if ($active_run_last_child and $active_run_last_child->nodeName eq 'w:t' and $node->nodeName eq 'w:t') { } 13 3 16
Condition50%3/6
$active_run_last_child and $active_run_last_child->nodeName eq "w:t" and $node->nodeName eq "w:t"
!ll&&!rl&&r
0313
$active_run_last_child and $active_run_last_child->nodeName eq "w:t"
!ll&&!rl&&r
0016
MC/DC33%1/3
$active_run_last_child and $active_run_last_child->nodeName eq "w:t" and $node->nodeName eq "w:t"
$active_run_last_child $active_run_last_child->nodeName eq "w:t" $node->nodeName eq "w:t"
Truth table50%2/4
A and B and C
A= $active_run_last_childB= $active_run_last_child->nodeName eq "w:t"C= $node->nodeName eq "w:t"
ABCresult
0XX0
10X0
1100
1111
399 && $active_run_last_child->nodeName eq 'w:t'
400 && $node->nodeName eq 'w:t'
401 ) {
402 13 ▶ $node->childNodes->foreach(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
403 13 my $child = shift;
404 13 $active_run_last_child->appendChild($child);
405 13 });
406  
407 13 $node->parentNode->removeChild($node);
408 }
409 else {
410 3 $active_run->appendChild($node);
411 3 ▶ if ( $node->isa('XML::LibXML::Element')
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("XML::LibXML::Element") or $node->isa("XML::LibXML::Text") and not $node->textContent =~ /^\s*$/) 0 3 3
Condition33%2/6
$node->isa("XML::LibXML::Element") or $node->isa("XML::LibXML::Text") and not $node->textContent =~ /^\s*$/
l!l&&r!l&&!r
003
$node->isa("XML::LibXML::Text") and not $node->textContent =~ /^\s*$/
!ll&&!rl&&r
030
MC/DC0%0/3
$node->isa("XML::LibXML::Element") or $node->isa("XML::LibXML::Text") and not $node->textContent =~ /^\s*$/
$node->isa("XML::LibXML::Element") $node->isa("XML::LibXML::Text") not $node->textContent =~ /^\s*$/
Truth table25%1/4
A or B and not(C)
A= $node->isa("XML::LibXML::Element")B= $node->isa("XML::LibXML::Text")C= not $node->textContent =~ /^\s*$/
ABCresult
1XX1
0111
00X0
0100
412 || ($node->isa('XML::LibXML::Text') && $node->textContent !~ /^\s*$/)
413 ) {
414 0 $active_run_last_child = $node;
415 }
416 }
417 13 });
418  
419 13 $run->parentNode->removeChild($run);
420 }
421 else {
422 18 $active_run = $run;
423 18 $active_run_props = $this_run_props;
424 19 ▶ $active_run_last_child = first {
Subroutine __ANON__: called CC=2 SCAR=6.9
425 19 ▶ $_->isa('XML::LibXML::Element')
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("XML::LibXML::Element") and $_->nodeName ne "w:rPr" 18 1 19
426 && $_->nodeName ne 'w:rPr'
427 18 } $run->childNodes->reverse->get_nodelist;
428 }
429 10 });
430  
431 10 for my $part ($self->referenced_parts) {
432 6 $part->merge_runs();
433 }
434  
435 10 return;
436 }
437  
438  
439 1 ▶sub replace_text {
Subroutine replace_text: called CC=2 SCAR=7.0
Pod documented
440 1 my $self = shift;
441 1 my $search = shift;
442 1 my $replace = shift;
443  
444 1 my $text_nodes = $self->xpc->findnodes(
445 '//w:t',
446 $self->xml->documentElement,
447 );
448  
449 1 ▶ $text_nodes->foreach(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
450 1 my $text = shift;
451  
452 1 ▶ $text->childNodes->foreach(sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
453 1 my $child = shift;
454 1 ▶ return unless $child->isa('XML::LibXML::Text');
Branch: 1 branch
BranchTrueFalseTotal
unless $child->isa("XML::LibXML::Text") 0 1 1
455  
456 1 $child->replaceDataString($search, $replace, 1);
457 1 });
458 1 });
459  
460 1 for my $part ($self->referenced_parts) {
461 0 $part->replace_text($search, $replace);
462 }
463  
464 1 return;
465 }
466  
467 {
468 2 my @EXPLICIT_REFERENCE_IDS = (
469 '//w:footerReference/@r:id',
470 '//w:headerReference/@r:id',
471 );
472  
473 2 my %IMPLICIT_REFERENCE_ELEMENTS = (
474 strict => {
475 '(//w:endnoteReference)[1]' => 'http://purl.oclc.org/ooxml/officeDocument/relationships/endnotes',
476 '(//w:footnoteReference)[1]' => 'http://purl.oclc.org/ooxml/officeDocument/relationships/footnotes',
477 '(//w:commentReference)[1]' => 'http://purl.oclc.org/ooxml/officeDocument/relationships/comments',
478 },
479 transitional => {
480 '(//w:endnoteReference)[1]' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes',
481 '(//w:footnoteReference)[1]' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes',
482 '(//w:commentReference)[1]' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
483 },
484 );
485  
486 43 ▶ sub referenced_parts {
Subroutine referenced_parts: called CC=5 SCAR=16.1
Pod undocumented
487 43 my $self = shift;
488  
489 43 my @parts;
490  
491 43 for my $ref_type (@EXPLICIT_REFERENCE_IDS) {
492 86 my $references = $self->xpc->findnodes(
493 $ref_type,
494 $self->xml->documentElement,
495 );
496  
497 16 ▶ $references->foreach(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
498 16 my $ref = shift;
499  
500 16 push @parts, $self->find_referenced_part_by_id($ref->value);
501 86 });
502 }
503  
504 43 ▶ my $strict = $self->is_strict ? 'strict' : 'transitional';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_strict ? : 27 16 43
505 43 for my $ref_type (keys %{ $IMPLICIT_REFERENCE_ELEMENTS{$strict} }) {
506 129 my $references = $self->xpc->findnodes(
507 $ref_type,
508 $self->xml->documentElement,
509 );
510  
511 129 ▶ next if not $references->size();
Branch: 1 branch
BranchTrueFalseTotal
unless $references->size 121 8 129
512  
513 push @parts, $self->find_referenced_part_by_type(
514 8 $IMPLICIT_REFERENCE_ELEMENTS{$strict}{$ref_type}
515 );
516 }
517  
518 43 return @parts;
519 }
520 }
521  
522 2 __PACKAGE__->meta->make_immutable();
523  
524 __END__
↑ Summary OOXML.pm »