blib/lib/XML/TreePP/Editor.pm

filter: Statementstmt 40.5% 248 / 611 Branchbran 21.7% 97 / 446 Conditioncond 27.0% 65 / 240 MC/DCmcdc 3.0% 4 / 130 Subroutinesub 60.0% 24 / 40 Podpod 100% 14 / 14 totaltotal 30.5% 452 / 1481 CC 326 SCAR 67.5
CC
326
Cov
32%
__ANON__
2756.0
__ANON__
1891.9
__ANON__
702.4
CRAP 858.0
↑ Summary
1 =pod
2  
3 =head1 NAME
4  
5 XML::TreePP::Editor - An editor for an XML::TreePP parsed XML document
6  
7 =head1 SYNOPSIS
8  
9 To use stand-alone:
10  
11 use strict;
12 use XML::TreePP;
13 use XML::TreePP::Editor;
14
15 my $tpp = XML::TreePP->new();
16 my $tree = $tpp->parse('file.xml');
17 my $tppe = new XML::TreePP::Editor();
18 $tppe->replace( $tree, '/path[2]/element[2]/node', { '-myattribute' => "new value" } );
19 $tppe->insert( $tree, '.', \%{<new_root_node>} );
20  
21 =head1 DESCRIPTION
22  
23 This module is used for editing a C<XML::TreePP> parsed XML Document.
24  
25 =head1 REQUIREMENTS
26  
27 The following perl modules are depended on by this module:
28  
29 =over 4
30  
31 =item * XML::TreePP
32  
33 =item * XML::TreePP::XMLPath >= version 0.61
34  
35 =back
36  
37 =head1 Editor PHILOSOPHY
38  
39 =head2 XML Node and Attribute Identification
40  
41 The identification of XML document nodes for modification is handled by the
42 C<XML::TreePP::XMLPath> module.
43  
44 The idenfication of attributes in XML nodes is via the C<attr_prefix> property
45 in the C<XML::TreePP> module.
46  
47 The idenfication of XML text (or CDATA) nodes is via the C<text_node_key>
48 property in the C<XML::TreePP> module.
49  
50 Please review the XMLPath PHILOSOPHY section in it's POD for further
51 information.
52  
53 =head2 C<XML::TreePP::XMLPath> dependency on C<XML::TreePP>
54  
55 The C<XML::TreePP::XMLPath> module has a dependence on C<XML::TreePP>
56 When C<XML::TreePP::Editor::tpp()> and C<XML::TreePP::Editor::tppx()> methods
57 are called without parameters, this module checks to see if either of these
58 objects have been previously created, and links them together.
59  
60 If you provide your own C<XML::TreePP> or C<XML::TreePP::XMLPath> objects, this
61 module does not attempt to link them together. Instead you would want to do
62 it yourself in the following fashion.
63  
64 my $tpp = new XML::TreePP;
65 my $tppx = new XML::TreePP::XMLPath;
66 $tppx->tpp($tpp);
67 my $tppe = new XML::TreePP::Editor( tpp => $tpp, tppx => $tppx );
68  
69 This is essentially similar to how the C<XML::TreePP::Editor::tpp()> and
70 C<XML::TreePP::Editor::tppx()> methods associate the objects.
71  
72 =head1 METHODS
73  
74 =cut
75  
76 package XML::TreePP::Editor;
77  
78 2 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 2 ▶use XML::TreePP;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 2 ▶use XML::TreePP::XMLPath 0.61;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶ use vars qw(@ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
88 2 @ISA = qw(Exporter);
89 2 @EXPORT = qw();
90 2 @EXPORT_OK = qw();
91  
92 2 ▶ use vars qw($REF_NAME);
Subroutine BEGIN: called CC=1 SCAR=0.0
93 2 $REF_NAME = "XML::TreePP::Editor"; # package name
94  
95 2 ▶ use vars qw( $VERSION $DEBUG $TPPKEYS );
Subroutine BEGIN: called CC=1 SCAR=0.0
96 2 $VERSION = '0.13';
97 2 $DEBUG = 0;
98 2 $TPPKEYS = "force_array force_hash cdata_scalar_ref user_agent http_lite lwp_useragent base_class elem_class xml_deref first_out last_out indent xml_decl output_encoding utf8_flag attr_prefix text_node_key ignore_error use_ixhash";
99 }
100  
101  
102 =pod
103  
104 =head2 tpp
105  
106 This module is an extension of the C<XML::TreePP module>. As such, it uses the
107 module in many different methods to parse XML Docuements, and when the user
108 calls the C<set()> and C<get()> methods to set and get properties specific to
109 the module.
110  
111 The C<XML::TreePP module>, is loaded upon requesting a new object.
112  
113 The caller can override the loaded instance of C<XML::TreePP> in favor of
114 another instance the caller posses, by providing it to this method.
115  
116 Additionally, this module's loaded instance of C<XML::TreePP> can be directly
117 accessed or retrieved through this method.
118  
119 =over 4
120  
121 =item * C<XML::TreePP>
122  
123 An instance of C<XML::TreePP> that this object should use instead of, when needed,
124 loading its own copy. If not provided, the currently loaded instance is
125 returned. If an instance is not loaded, an instance is loaded and then returned.
126  
127 =item * I<returns>
128  
129 Returns the result of setting an instance of C<XML::TreePP> in this object.
130 Or returns the internally loaded instance of C<XML::TreePP>.
131 Or loads a new instance of C<XML::TreePP> and returns it.
132  
133 =back
134  
135 $tppe->tpp( new XML::TreePP ); # Sets the XML::TreePP instance to be used by this object
136 my $tppobj = $tppe->tpp(); # Retrieve the currently loaded XML::TreePP instance
137  
138 =cut
139  
140 0 ▶sub tpp(@) {
Subroutine tpp: not called CC=8 SCAR=42.8
Pod documented
141 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
142 0 ▶ if (!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self) { } 0 0 0
143 0 return new XML::TreePP;
144 } else {
145 # If being given the object, set it and return result
146 0 ▶ return $self->{'tpp'} = shift if @_ >= 1 && ref($_[0]) eq "XML::TreePP";
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 1 and ref $_[0] eq "XML::TreePP" 0 0 0
Condition0%0/3
@_ >= 1 and ref $_[0] eq "XML::TreePP"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 1 and ref $_[0] eq "XML::TreePP"
@_ >= 1 ref $_[0] eq "XML::TreePP"
Truth table0%0/3
A and B
A= @_ >= 1B= ref $_[0] eq "XML::TreePP"
ABresult
0X0
100
111
147 # If wanting object, and XMLPath object exists, retrieve it, set it, and return it
148 0 ▶ if ((defined $self->{'tppx'}) && (ref($self->{'tppx'}) eq "XML::TreePP::XMLPath")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tppx"} and ref $self->{"tppx"} eq "XML::TreePP::XMLPath") 0 0 0
Condition0%0/3
defined $self->{"tppx"} and ref $self->{"tppx"} eq "XML::TreePP::XMLPath"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"tppx"} and ref $self->{"tppx"} eq "XML::TreePP::XMLPath"
defined $self->{"tppx"} ref $self->{"tppx"} eq "XML::TreePP::XMLPath"
Truth table0%0/3
A and B
A= defined $self->{"tppx"}B= ref $self->{"tppx"} eq "XML::TreePP::XMLPath"
ABresult
0X0
100
111
149 0 $self->{'tpp'} = $self->{'tppx'}->tpp();
150 0 return $self->{'tpp'};
151 }
152 # If wanting object and XMLPath object does not exist, create it and return it
153 0 $self->{'tpp'} = new XML::TreePP;
154 0 return $self->{'tpp'};
155 }
156 }
157  
158  
159 =pod
160  
161 =head2 tppx
162  
163 This module is an extension of the C<XML::TreePP::XMLPath> module. As such,
164 it uses the module in many different methods to access C<XML::TreePP> parsed XML
165 Documents, and when the user calls the C<set()> and C<get()> methods to set
166 and get properties specific to the module.
167  
168 The C<XML::TreePP::XMLPath> module, is loaded upon requesting a new object.
169  
170 The caller can override the loaded instance of C<XML::TreePP::XMLPath> in favor of
171 another instance the caller posses, by proving it to this method.
172  
173 Additionally, this module's loaded instance of C<XML::TreePP::XMLPath> can be
174 directly accessed or retrieved through this method.
175  
176 =over 4
177  
178 =item * C<XML::TreePP::XMLPath>
179  
180 An instance of C<XML::TreePP::XMLPath> that this object should use instead of,
181 when needed, loading its own copy. If not provided, the currently loaded
182 instance is returned. If an instance is not already loaded, a new instance is
183 loaded and then returned.
184  
185 =item * I<returns>
186  
187 Returns the result of setting an instance of C<XML::TreePP::XMLPath> in this object.
188 Or returns the internally loaded instance of C<XML::TreePP::XMLPath>.
189 Or loads a new instance of C<XML::TreePP::XMLPath> and returns it.
190  
191 =back
192  
193 $tppe->tppx( new XML::TreePP::XMLPath ); # Sets the XML::TreePP instance to be used by this object
194 my $tppxobj = $tppe->tppx(); # Retrieve the currently loaded XML::TreePP instance
195  
196 =cut
197  
198 10 ▶sub tppx(@) {
Subroutine tppx: called CC=8 SCAR=26.5
Pod documented
199 10 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 10 0 10
Condition50%1/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
100
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table50%1/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
200 10 ▶ if (!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self) { } 0 10 10
201 0 return new XML::TreePP::XMLPath;
202 } else {
203 # If being given the object, set it and return result
204 10 ▶ return $self->{'tppx'} = shift if @_ >= 1 && ref($_[0]) eq "XML::TreePP::XMLPath";
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 1 and ref $_[0] eq "XML::TreePP::XMLPath" 0 10 10
Condition33%1/3
@_ >= 1 and ref $_[0] eq "XML::TreePP::XMLPath"
!ll&&!rl&&r
1000
MC/DC0%0/2
@_ >= 1 and ref $_[0] eq "XML::TreePP::XMLPath"
@_ >= 1 ref $_[0] eq "XML::TreePP::XMLPath"
Truth table33%1/3
A and B
A= @_ >= 1B= ref $_[0] eq "XML::TreePP::XMLPath"
ABresult
0X0
100
111
205 # If wanting object, and XML::TreePP object exists, create it, associate it, and return it
206 # Create
207 10 $self->{'tppx'} = new XML::TreePP::XMLPath;
208 # Associate
209 10 ▶ if ((defined $self->{'tpp'}) && (ref($self->{'tpp'}) eq "XML::TreePP")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tpp"} and ref $self->{"tpp"} eq "XML::TreePP") 0 10 10
Condition33%1/3
defined $self->{"tpp"} and ref $self->{"tpp"} eq "XML::TreePP"
!ll&&!rl&&r
1000
MC/DC0%0/2
defined $self->{"tpp"} and ref $self->{"tpp"} eq "XML::TreePP"
defined $self->{"tpp"} ref $self->{"tpp"} eq "XML::TreePP"
Truth table33%1/3
A and B
A= defined $self->{"tpp"}B= ref $self->{"tpp"} eq "XML::TreePP"
ABresult
0X0
100
111
210 0 $self->{'tppx'}->tpp( $self->{'tpp'} );
211 }
212 # Return
213 10 return $self->{'tppx'};
214 }
215 }
216  
217  
218 =pod
219  
220 =head2 set
221  
222 Set the value for a property in this object instance.
223 This method can only be accessed in object oriented style.
224  
225 =over 4
226  
227 =item * C<propertyname>
228  
229 The property to set the value for.
230  
231 =item * C<propertyvalue>
232  
233 The value of the property to set.
234 If no value is given, the property is deleted.
235  
236 =item * I<returns>
237  
238 Returns the result of setting the value of the property, or the result of
239 deleting the property.
240  
241 =back
242  
243 $tppe->set( 'property_name' ); # deletes the property property_name
244 $tppe->set( 'property_name' => 'val' ); # sets the value of property_name
245  
246 =cut
247  
248 0 ▶sub set(@) {
Subroutine set: not called CC=5 SCAR=34.0
Pod documented
249 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
250 0 my %args = @_;
251 0 ▶ while (my ($key,$val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
252 0 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
253 0 $self->{$key} = $val;
254 }
255 else {
256 0 delete $self->{$key};
257 }
258 }
259 }
260  
261  
262 =pod
263  
264 =head2 get
265  
266 Retrieve the value set for a property in this object instance.
267 This method can only be accessed in object oriented style.
268  
269 =over 4
270  
271 =item * C<propertyname>
272  
273 The property to get the value for
274  
275 =item * I<returns>
276  
277 Returns the value of the property requested
278  
279 =back
280  
281 $tppe->get( 'property_name' );
282  
283 =cut
284  
285 10 ▶sub get(@) {
Subroutine get: called CC=4 SCAR=14.9
Pod documented
286 10 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef 10 0 10
Condition50%1/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef
l!l
100
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or return undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table50%1/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
287 10 my $key = shift;
288 10 ▶ return $self->{$key} if exists $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$key} 0 10 10
289 10 return undef;
290 }
291  
292  
293 =pod
294  
295 =head2 new
296  
297 Create a new object instances of this module.
298  
299 =over 4
300  
301 =item * B<tpp>
302  
303 An instance of C<XML::TreePP> to be used instead of letting this module load
304 its own.
305  
306 =item * B<tppx>
307  
308 An instance of C<XML::TreePP::XMLPath> to be used instead of letting this
309 module load its own.
310  
311 =item * B<debug>
312  
313 The debug level to set on this object.
314  
315 =item * I<returns>
316  
317 An object instance of this module.
318  
319 =back
320  
321 my $cfg = new XML::TreePP::Editor();
322  
323 =cut
324  
325 1 ▶sub new () {
Subroutine new: called CC=5 SCAR=17.6
Pod documented
326 1 my $pkg = shift;
327 1 ▶ my $class = ref($pkg) || $pkg;
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
328 1 my $self = bless {}, $class;
329 1 my %args = @_;
330  
331 1 ▶ $self->tpp($args{'tpp'}) if exists $args{'tpp'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"tpp"} 0 1 1
332 1 ▶ $self->tppx($args{'tppx'}) if exists $args{'tppx'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"tppx"} 0 1 1
333 1 ▶ $args{'debug'} ||= $DEBUG;
Condition33%1/3
$args{"debug"} ||= $XML::TreePP::Editor::DEBUG
l!l&&r!l&&!r
001
MC/DC0%0/2
$args{"debug"} ||= $XML::TreePP::Editor::DEBUG
$args{"debug"} $XML::TreePP::Editor::DEBUG
Truth table33%1/3
A ||= B
A= $args{"debug"}B= $XML::TreePP::Editor::DEBUG
ABresult
1X1
011
000
334 1 $self->debug($args{'debug'});
335  
336 1 return $self;
337 }
338  
339  
340 =pod
341  
342 =head2 debug
343  
344 Set the debug level
345  
346 =over 4
347  
348 =item * B<val> - optional
349  
350 A value that is >= 0
351  
352 =item * I<returns>
353  
354 If passing in B<val>, then the result of setting that value to the object's debug variable.
355  
356 If not passing in B<val>, then the current set value of the object's debug variable.
357  
358 =back
359  
360 $tppe->debug(0); # turn off debug
361 $tppe->debug(9); # turn on debug with value of 9
362 my $debuglevel = $tppe->debug();
363  
364 =cut
365  
366 1 ▶sub debug {
Subroutine debug: called CC=3 SCAR=15.1
Pod documented
367 1 my $self = shift;
368 1 ▶ if (@_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) 0 1 1
369 0 ▶ return $DEBUG if !defined $self->{'_debug'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_debug"} 0 0 0
370 0 return $self->{'_debug'};
371 }
372 1 return $self->{'_debug'} = shift;
373 }
374  
375  
376 =pod
377  
378 =head2 modify
379  
380 modify( XMLTree, XMLPath, %OPTIONS )
381  
382 where %options = ( action => %value )
383  
384 and action is one of ( insert, replace, delete, mergeadd, mergereplace, mergedelete, mergeappend )
385  
386 and %value is a XML Node Hash, either a partial node or full node
387  
388 =over 4
389  
390 =item * B<XML::TreePP parsed tree>
391  
392 The parsed XML Document.
393  
394 =item * B<XML::TreePP::XMLPath path>
395  
396 The XML Path to the node, attribute or element to modify
397  
398 =item * B<options>
399  
400 The options for modifying the node.
401  
402 =over 4
403  
404 =item * insert => C<\%node> - insert the new node at XMLPath
405  
406 =item * replace => C<\%node> - replace the node at XMLPath with this new node
407  
408 =item * delete => C<undef> - delete the node at the XMLPath
409  
410 =item * mergeadd => C<\%node> - merge this node into the node at XMLPath,
411 only adding elements and attributes that do not exist
412  
413 =item * mergereplace => C<\%node> - merge this node into the node at XMLPath,
414 replacing elements and attributes, and adding them if they do not exist
415  
416 =item * mergedelete => C<\%node> - merge this node into the node at XMLPath,
417 deleting elements and attributes that exist in both nodes
418  
419 =item * mergeappend => C<\%node> - merge this node into the node at XMLPath,
420 appending the values of text elements
421  
422 =back
423  
424 B<note:> This method uses the values retrieved from
425 $self->tpp()->get('attr_prefix') and $self->tpp()->get('text_node_key') to
426 define how to interpret how to identify attributes and text (CDATA) nodes.
427  
428 =back
429  
430 Example:
431  
432 my $xmltree => { path => { to => { node => "Brown bears" } } };
433 $tppe->modify( $xmltree, '/path/to/node', mergeappend => { '#text' => " with blue shoes." } )
434 # or: $tppe->modify( $xmltree, '/path/to/node/#text', mergeappend => { '#text' => " with blue shoes." } )
435 # or: $tppe->modify( $xmltree, '/path/to/node/#text', mergeappend => " with blue shoes." )
436 print $xmltree->{'path'}->{'to'}->{'node'};
437
438 output:
439
440 Brown bears with blue shoes.
441  
442 =cut
443  
444 10 ▶sub modify (@) {
Subroutine modify: called CC=17 SCAR=47.1
Pod documented
445 10 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 10 0 10
Condition50%1/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
100
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table50%1/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
446 0 ▶ unless (@_ >= 3) { carp 'method modify() requires at least three arguments.'; return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ >= 3) 0 10 10
447 10 my $xtree = shift;
448 10 my $xmlpath = shift; # XML::TreePP::XMLPath
449 10 my %options = @_; # replace=>\%val; insert=>\%val; etc.
450 10 my $numAffected = 0;
451  
452 10 local $Data::Dumper::Indent = 0;
453 10 local $Data::Dumper::Purity = 1;
454 10 local $Data::Dumper::Terse = 1;
455  
456 10 my ($tpp,$tppx,$xml_text_id,$xml_attr_id);
457  
458 10 ▶ if ((defined $self) && (defined $self->get('tpp'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self and defined $self->get('tpp')) { } 0 10 10
Condition33%1/3
defined $self and defined $self->get("tpp")
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $self and defined $self->get("tpp")
defined $self defined $self->get("tpp")
Truth table33%1/3
A and B
A= defined $selfB= defined $self->get("tpp")
ABresult
0X0
100
111
459 0 ▶ $tpp = $self ? $self->tpp() : tpp();
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
460 0 ▶ $tppx = $self ? $self->tppx() : tppx();
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
461 0 ▶ $xml_text_id = $tpp->get( 'text_node_key' ) || '#text';
Condition0%0/2
$tpp->get('text_node_key') || '#text'
l!l
00
MC/DC0%0/1
$tpp->get('text_node_key') || '#text'
$tpp->get('text_node_key')
Truth table0%0/2
A
A= $tpp->get('text_node_key')
Aresult
11
00
462 0 ▶ $xml_attr_id = $tpp->get( 'attr_prefix' ) || '-';
Condition0%0/2
$tpp->get('attr_prefix') || '-'
l!l
00
MC/DC0%0/1
$tpp->get('attr_prefix') || '-'
$tpp->get('attr_prefix')
Truth table0%0/2
A
A= $tpp->get('attr_prefix')
Aresult
11
00
463 } else {
464 10 $xml_text_id = '#text';
465 10 $xml_attr_id = '-';
466 }
467  
468 6 ▶ my $whatisnode = sub ($) {
Subroutine __ANON__: called CC=6 SCAR=18.7
469 6 my $nodename = shift;
470 6 ▶ return undef if ref($nodename);
Branch: 1 branch
BranchTrueFalseTotal
if ref $nodename 0 6 6
471 6 ▶ return "text" if $nodename eq $xml_text_id;
Branch: 1 branch
BranchTrueFalseTotal
if $nodename eq $xml_text_id 0 6 6
472 6 ▶ return "attribute" if $nodename =~ /^$xml_attr_id\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $nodename =~ /^$xml_attr_id\w+$/ 2 4 6
473 4 ▶ return "parent" if $nodename eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $nodename eq ".." 0 4 4
474 4 ▶ return "current" if $nodename eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $nodename eq "." 0 4 4
475 4 return "element";
476 10 };
477 6 ▶ my $isnodetype = sub ($) {
Subroutine __ANON__: called CC=2 SCAR=6.9
478 6 my $nodename = shift;
479 6 my $compare = shift;
480 6 ▶ return 1 if $whatisnode->($nodename) eq $compare;
Branch: 1 branch
BranchTrueFalseTotal
if &$whatisnode($nodename) eq $compare 1 5 6
481 5 return 0;
482 10 };
483  
484 10 ▶ my $nodeMerge = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
485 0 ▶ $nodeMerge = sub (@) {
Subroutine __ANON__: not called CC=52 SCAR=79.2
486 0 my $parentnode = shift; # ref - must be HASH ref, or ARRAY if merging to multiple parents
487 0 my $childname = shift; # ref->ref # merge into the node with this child name | or append to $stringname of existing child node
488 0 my $childpos = shift; # ref->ref->[#] - can be undef # merge into the node at this position, undef to merge into all | or append to $stringname of existing child node at this position
489 0 my $stringname = shift; # ref->ref->[#]->name - can be undef # append to this $stringname of the child node
490 0 my $value = shift;
491 0 my %options = @_;
492 0 ▶ my $mergetype = $options{'mergetype'} || "add"; # add|replace|delete|append
Condition0%0/2
$options{'mergetype'} || 'add'
l!l
00
MC/DC0%0/1
$options{'mergetype'} || 'add'
$options{'mergetype'}
Truth table0%0/2
A
A= $options{'mergetype'}
Aresult
11
00
493 0 my $result = 0;
494  
495 0 ▶ if (!ref($parentnode)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode) { } 0 0 0
elsif (ref $parentnode eq 'ARRAY') { } 0 0 0
elsif (ref $parentnode eq 'HASH') { } 0 0 0
496 0 croak "Cannot merge a child node to a non referencing parent node.";
497 0 return undef;
498 } elsif (ref($parentnode) eq "ARRAY") {
499 0 ▶ if (@{$parentnode} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parentnode;} == 0) 0 0 0
500 0 push(@{$parentnode}, {});
501 }
502 0 foreach my $single_parentnode (@{$parentnode}) {
503 0 my $newresult = $nodeMerge->($single_parentnode,$childname,$childpos,$stringname,$value);
504 0 $result += $newresult;
505 }
506 } elsif (ref($parentnode) eq "HASH") {
507 # In every case (but for appending to $stringname), we are merging into an existing child node
508 0 my $newchildnode;
509 0 ▶ if ((!ref($value)) && (defined $value) && (defined $stringname)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $value and defined $value and defined $stringname) { } 0 0 0
elsif (not ref $value || defined $stringname) { } 0 0 0
elsif (ref $value) { } 0 0 0
Condition0%0/6
not ref $value and defined $value and defined $stringname
!ll&&!rl&&r
000
not ref $value and defined $value
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $value and defined $value and defined $stringname
not ref $value defined $value defined $stringname
Truth table0%0/4
not(A) and B and C
A= not ref $valueB= defined $valueC= defined $stringname
ABCresult
0XX0
10X0
1100
1111
510 0 $newchildnode = [{ $stringname => $value }];
511 ▶ } elsif ((!ref($value)) && (!defined $stringname)) {
Condition0%0/3
ref $value || defined $stringname
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $value || defined $stringname
ref $value defined $stringname
Truth table0%0/3
A || B
A= ref $valueB= defined $stringname
ABresult
1X1
011
000
512 0 $newchildnode = [{ $xml_text_id => $value }];
513 } elsif (ref($value)) {
514 0 ▶ $newchildnode = [ $value ] if ref($value) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 0 0 0
515 0 ▶ $newchildnode = $value if ref($value) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 0 0
516 } else {
517 0 return undef;
518 }
519  
520 0 ▶ if (ref($parentnode->{$childname}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'ARRAY') { } 0 0 0
521 0 ▶ if ((defined $childpos) && ($childpos >= 1) && ($childpos <= @{$parentnode->{$childname}})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}) { } 0 0 0
elsif (not defined $childpos) { } 0 0 0
Condition0%0/6
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
!ll&&!rl&&r
000
defined $childpos and $childpos >= 1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
defined $childpos $childpos >= 1 $childpos <= @{$parentnode->{$childname};}
Truth table0%0/4
A and B and C
A= defined $childposB= $childpos >= 1C= $childpos <= @{$parentnode->{$childname};}
ABCresult
0XX0
10X0
1100
1111
522 0 ▶ if ((defined $stringname) && ($isnodetype->($stringname, "text"))) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $stringname and &$isnodetype($stringname, 'text')) { } 0 0 0
elsif (defined $stringname) { } 0 0 0
Condition0%0/3
defined $stringname and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stringname and &$isnodetype($stringname, "text")
defined $stringname &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= defined $stringnameB= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
523 # append to #text
524 0 ▶ if (ref($parentnode->{$childname}->[($childpos - 1)]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$childpos - 1] eq 'HASH') { } 0 0 0
elsif (not ref $parentnode->{$childname}[$childpos - 1]) { } 0 0 0
525 0 $parentnode->{$childname}->[($childpos - 1)]->{$stringname} .= $newchildnode->[0]->{$stringname};
526 0 $result++;
527 } elsif (!ref($parentnode->{$childname}->[($childpos - 1)])) {
528 0 $parentnode->{$childname}->[($childpos - 1)] .= $newchildnode->[0]->{$stringname};
529 0 $result++;
530 }
531 } elsif (defined $stringname) {
532 # do not replace @attributes, parentnode is priority on keeping attribute values - use replace to replace them
533 # $parentnode->{$childname}->[($childpos - 1)]->{$stringname} = $newchildnode->[0]->{$stringname};
534 # $result++;
535 } else {
536 0 foreach my $vk (keys %{$newchildnode->[0]}) {
537 0 ▶ if (!exists $parentnode->{$childname}->[($childpos - 1)]->{$vk}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $parentnode->{$childname}[$childpos - 1]{$vk}) { } 0 0 0
elsif (exists $parentnode->{$childname}[$childpos - 1]{$vk}) { } 0 0 0
538 0 $parentnode->{$childname}->[($childpos - 1)]->{$vk} = $newchildnode->[0]->{$vk};
539 0 $result++;
540 } elsif (exists $parentnode->{$childname}->[($childpos - 1)]->{$vk}) {
541 0 ▶ if ($isnodetype->($vk, "text")) {
Branch: 3 branches
BranchTrueFalseTotal
if (&$isnodetype($vk, 'text')) { } 0 0 0
elsif (&$isnodetype($vk, 'attribute')) { } 0 0 0
elsif (ref $parentnode->{$childname}[$childpos - 1]{$vk} eq 'ARRAY') { } 0 0 0
542 # Merge #text/CDATA
543 0 $parentnode->{$childname}->[($childpos - 1)]->{$vk} = ($parentnode->{$childname}->[($childpos - 1)]->{$vk} . $newchildnode->[0]->{$vk})
544 } elsif ($isnodetype->($vk, "attribute")) {
545 # Do not replace attributes
546 #$parentnode->{$childname}->[($childpos - 1)]->{$vk} = $newchildnode->[0]->{$vk} if $isnodetype->($vk, "attribute");
547 } elsif (ref($parentnode->{$childname}->[($childpos - 1)]->{$vk}) eq "ARRAY") {
548 # append new merged ones
549 0 ▶ push (@{$parentnode->{$childname}->[($childpos - 1)]->{$vk}},$newchildnode->[0]->{$vk}) if ref($newchildnode->[0]->{$vk}) ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $newchildnode->[0]{$vk} ne "ARRAY" 0 0 0
550 0 ▶ push (@{$parentnode->{$childname}->[($childpos - 1)]->{$vk}},@{$newchildnode->[0]->{$vk}}) if ref($newchildnode->[0]->{$vk}) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $newchildnode->[0]{$vk} eq "ARRAY" 0 0 0
551 0 $result++;
552 } else {
553 # convert to array, and append new merged ones
554 0 ▶ $parentnode->{$childname}->[($childpos - 1)]->{$vk} = [$parentnode->{$childname}->[($childpos - 1)]->{$vk},$newchildnode->[0]->{$vk}] if ref($newchildnode->[0]->{$vk}) ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $newchildnode->[0]{$vk} ne "ARRAY" 0 0 0
555 0 ▶ $parentnode->{$childname}->[($childpos - 1)]->{$vk} = [$parentnode->{$childname}->[($childpos - 1)]->{$vk},@{$newchildnode->[0]->{$vk}}] if ref($newchildnode->[0]->{$vk}) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $newchildnode->[0]{$vk} eq "ARRAY" 0 0 0
556 0 $result++;
557 }
558 }
559 }
560 }
561 } elsif (!defined $childpos) {
562 0 my $i = 0;
563 0 ▶ while ($i < @{$parentnode->{$childname}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$parentnode->{$childname};}) 0 0 0
564 0 ▶ if ((defined $stringname) && ($isnodetype->($stringname, "text"))) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $stringname and &$isnodetype($stringname, 'text')) { } 0 0 0
elsif (defined $stringname) { } 0 0 0
Condition0%0/3
defined $stringname and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stringname and &$isnodetype($stringname, "text")
defined $stringname &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= defined $stringnameB= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
565 0 ▶ if (ref($parentnode->{$childname}->[($childpos - 1)]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$childpos - 1] eq 'HASH') { } 0 0 0
elsif (not ref $parentnode->{$childname}[$childpos - 1]) { } 0 0 0
566 0 $parentnode->{$childname}->[$i]->{$stringname} .= $newchildnode->[0]->{$stringname};
567 0 $result++;
568 } elsif (!ref($parentnode->{$childname}->[($childpos - 1)])) {
569 0 $parentnode->{$childname}->[$i] .= $newchildnode->[0]->{$stringname};
570 0 $result++;
571 }
572 } elsif (defined $stringname) {
573 0 $parentnode->{$childname}->[$i]->{$stringname} = $newchildnode->[0]->{$stringname};
574 0 $result++;
575 } else {
576 0 $result += $nodeMerge->($parentnode,$childname,$i,undef,$newchildnode->[0]);
577 }
578 0 $i++;
579 }
580 } else {
581 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
582 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
583 0 return undef;
584 }
585 } else {
586 0 ▶ if ((!defined $childpos) || ($childpos == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $childpos or $childpos == 1) { } 0 0 0
Condition0%0/3
not defined $childpos or $childpos == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $childpos or $childpos == 1
not defined $childpos $childpos == 1
Truth table0%0/3
not(A) or B
A= not defined $childposB= $childpos == 1
ABresult
1X1
011
000
587 0 ▶ if ((defined $stringname) && ($isnodetype->($stringname, "text"))) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $stringname and &$isnodetype($stringname, 'text')) { } 0 0 0
elsif (defined $stringname) { } 0 0 0
Condition0%0/3
defined $stringname and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stringname and &$isnodetype($stringname, "text")
defined $stringname &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= defined $stringnameB= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
588 # The parent node keeps all attribute values, but combines #text or CDATA
589 0 ▶ if (ref($parentnode->{$childname}) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'HASH') { } 0 0 0
elsif (not ref $parentnode->{$childname}) { } 0 0 0
590 0 $parentnode->{$childname}->{$stringname} .= $newchildnode->[0]->{$stringname};
591 0 $result++;
592 } elsif (!ref($parentnode->{$childname})) {
593 0 $parentnode->{$childname} .= $newchildnode->[0];
594 0 $result++;
595 }
596 } elsif (defined $stringname) {
597 # The parent node keeps all attribute values - use replace to replace them
598 # $parentnode->{$childname}->{$stringname} = $newchildnode->[0]->{$stringname};
599 } else {
600 0 $parentnode->{$childname} = $newchildnode->[0];
601 0 $result++;
602 }
603 } else {
604 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
605 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
606 0 return undef;
607 }
608 }
609 }
610 0 return $result;
611 10 };
612  
613 10 ▶ my $nodeMergeActionSingle = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
614 5 ▶ $nodeMergeActionSingle = sub (@) {
Subroutine __ANON__: called CC=20 SCAR=32.1
615 5 my $targetnode = shift;
616 5 my $mergenode = shift;
617 5 my $action = shift; # add | append | replace | delete
618 5 my $result = 0;
619 # print Dumper({ targetnode => $targetnode, mergenode => $mergenode, action => $action });
620 5 ▶ unless ( (ref($targetnode) eq "HASH") && (ref($mergenode) eq "HASH") && (defined $action) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $targetnode eq "HASH" and ref $mergenode eq "HASH" and defined $action) 0 5 5
Condition33%2/6
ref $targetnode eq "HASH" and ref $mergenode eq "HASH" and defined $action
!ll&&!rl&&r
005
ref $targetnode eq "HASH" and ref $mergenode eq "HASH"
!ll&&!rl&&r
005
MC/DC0%0/3
ref $targetnode eq "HASH" and ref $mergenode eq "HASH" and defined $action
ref $targetnode eq "HASH" ref $mergenode eq "HASH" defined $action
Truth table25%1/4
A and B and C
A= ref $targetnode eq "HASH"B= ref $mergenode eq "HASH"C= defined $action
ABCresult
0XX0
10X0
1100
1111
621 0 return undef;
622 }
623 5 foreach my $vk (keys %{$mergenode}) {
624 8 ▶ if ($action eq "mergeadd") {
Branch: 4 branches
BranchTrueFalseTotal
if ($action eq 'mergeadd') { } 2 6 8
elsif ($action eq 'mergeappend') { } 3 3 6
elsif ($action eq 'mergereplace') { } 2 1 3
elsif ($action eq 'mergedelete') { } 1 0 1
625 2 ▶ if ( (exists $targetnode->{$vk})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $targetnode->{$vk} and ref $targetnode->{$vk}) { } 0 2 2
elsif (exists $targetnode->{$vk} and not ref $targetnode->{$vk} and defined $targetnode->{$vk} and $targetnode->{$vk} ne '') { } 1 1 2
Condition66%2/3
exists $targetnode->{$vk} and ref $targetnode->{$vk}
!ll&&!rl&&r
110
MC/DC0%0/2
exists $targetnode->{$vk} and ref $targetnode->{$vk}
exists $targetnode->{$vk} ref $targetnode->{$vk}
Truth table66%2/3
A and B
A= exists $targetnode->{$vk}B= ref $targetnode->{$vk}
ABresult
0X0
100
111
626 && (ref($targetnode->{$vk})) ) {
627 # do nothing, already exists as a referenced element
628 ▶ } elsif ( (exists $targetnode->{$vk})
Condition66%6/9
exists $targetnode->{$vk} and not ref $targetnode->{$vk} and defined $targetnode->{$vk} and $targetnode->{$vk} ne ""
!ll&&!rl&&r
101
exists $targetnode->{$vk} and not ref $targetnode->{$vk} and defined $targetnode->{$vk}
!ll&&!rl&&r
101
exists $targetnode->{$vk} and not ref $targetnode->{$vk}
!ll&&!rl&&r
101
MC/DC25%1/4
exists $targetnode->{$vk} and not ref $targetnode->{$vk} and defined $targetnode->{$vk} and $targetnode->{$vk} ne ""
exists $targetnode->{$vk} not ref $targetnode->{$vk} defined $targetnode->{$vk} $targetnode->{$vk} ne ""
Truth table40%2/5
A and not(B) and C and D
A= exists $targetnode->{$vk}B= not ref $targetnode->{$vk}C= defined $targetnode->{$vk}D= $targetnode->{$vk} ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
629 && (!ref($targetnode->{$vk}))
630 && (defined $targetnode->{$vk})
631 && ($targetnode->{$vk} ne "") ) {
632 # do nothing, already exists as text string or CDATA
633 } else {
634 1 $targetnode->{$vk} = $mergenode->{$vk};
635 1 $result++;
636 }
637 } elsif ($action eq "mergeappend") {
638 # we can only append if the target value and merge value are text or CDATA
639 3 ▶ if ( ($isnodetype->($vk, "text"))
Branch: 1 branch
BranchTrueFalseTotal
if (&$isnodetype($vk, "text") or &$isnodetype($vk, "attribute") or not ref $targetnode->{$vk} and $mergenode->{$vk} =~ /\w+/) 2 1 3
Condition77%7/9
&$isnodetype($vk, "text") or &$isnodetype($vk, "attribute") or not ref $targetnode->{$vk} and $mergenode->{$vk} =~ /\w+/
l!l&&r!l&&!r
111
&$isnodetype($vk, "text") or &$isnodetype($vk, "attribute")
l!l&&r!l&&!r
012
not ref $targetnode->{$vk} and $mergenode->{$vk} =~ /\w+/
!ll&&!rl&&r
101
MC/DC50%2/4
&$isnodetype($vk, "text") or &$isnodetype($vk, "attribute") or not ref $targetnode->{$vk} and $mergenode->{$vk} =~ /\w+/
&$isnodetype($vk, "text") &$isnodetype($vk, "attribute") not ref $targetnode->{$vk} $mergenode->{$vk} =~ /\w+/
Truth table60%3/5
A or B or not(C) and D
A= &$isnodetype($vk, "text")B= &$isnodetype($vk, "attribute")C= not ref $targetnode->{$vk}D= $mergenode->{$vk} =~ /\w+/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
640 || ($isnodetype->($vk, "attribute"))
641 || ((!ref($targetnode->{$vk})) && ($mergenode->{$vk} =~ /\w+/)) ) {
642 2 $targetnode->{$vk} .= $mergenode->{$vk};
643 2 $result++;
644 }
645 } elsif ($action eq "mergereplace") {
646 2 $targetnode->{$vk} = $mergenode->{$vk};
647 2 $result++;
648 } elsif ($action eq "mergedelete") {
649 1 ▶ if (exists $targetnode->{$vk}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $targetnode->{$vk}) 1 0 1
650 1 delete $targetnode->{$vk};
651 1 $result++;
652 }
653 }
654 }
655 5 return $result;
656 10 };
657 10 ▶ my $nodeMergeAction = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
658 5 ▶ $nodeMergeAction = sub (@) {
Subroutine __ANON__: called CC=59 SCAR=75.5
659 5 my $parentnode = shift; # ref - must be HASH ref, or ARRAY if merging to multiple parents
660 5 my $childname = shift; # ref->ref # merge into the node with this child name | or append to $stringname of existing child node
661 5 my $childpos = shift; # ref->ref->[#] - can be undef # merge into the node at this position, undef to merge into all | or append to $stringname of existing child node at this position
662 5 my $stringname = shift; # ref->ref->[#]->name - can be undef # append to this $stringname of the child node
663 5 my $value = shift;
664 5 my %options = @_;
665 5 ▶ my $action = $options{'mergetype'} || "add"; # add|replace|delete|append
Condition50%1/2
$options{'mergetype'} || 'add'
l!l
50
MC/DC0%0/1
$options{'mergetype'} || 'add'
$options{'mergetype'}
Truth table50%1/2
A
A= $options{'mergetype'}
Aresult
11
00
666 5 my $result = 0;
667  
668 5 ▶ if (!ref($parentnode)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode) { } 0 5 5
elsif (ref $parentnode eq 'ARRAY') { } 0 5 5
elsif (ref $parentnode eq 'HASH') { } 5 0 5
669 0 croak "Cannot merge a child node to a non referencing parent node.";
670 0 return undef;
671 } elsif (ref($parentnode) eq "ARRAY") {
672 0 ▶ if (@{$parentnode} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parentnode;} == 0) 0 0 0
673 0 push(@{$parentnode}, {});
674 }
675 0 foreach my $single_parentnode (@{$parentnode}) {
676 0 my $newresult = $nodeMergeAction->($single_parentnode,$childname,$childpos,$stringname,$value);
677 0 $result += $newresult;
678 }
679 } elsif (ref($parentnode) eq "HASH") {
680 # In every case (but for appending to $stringname), we are merging into an existing child node
681 5 my $newchildnode;
682 5 ▶ if ((!ref($value)) && (defined $value) && (defined $stringname)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $value and defined $value and defined $stringname) { } 0 5 5
elsif (not ref $value || defined $stringname) { } 0 5 5
elsif (ref $value) { } 5 0 5
Condition33%2/6
not ref $value and defined $value and defined $stringname
!ll&&!rl&&r
500
not ref $value and defined $value
!ll&&!rl&&r
500
MC/DC0%0/3
not ref $value and defined $value and defined $stringname
not ref $value defined $value defined $stringname
Truth table25%1/4
not(A) and B and C
A= not ref $valueB= defined $valueC= defined $stringname
ABCresult
0XX0
10X0
1100
1111
683 0 $newchildnode = [{ $stringname => $value }];
684 ▶ } elsif ((!ref($value)) && (!defined $stringname)) {
Condition33%1/3
ref $value || defined $stringname
l!l&&r!l&&!r
500
MC/DC0%0/2
ref $value || defined $stringname
ref $value defined $stringname
Truth table33%1/3
A || B
A= ref $valueB= defined $stringname
ABresult
1X1
011
000
685 0 $newchildnode = [{ $xml_text_id => $value }];
686 } elsif (ref($value)) {
687 5 ▶ $newchildnode = [ $value ] if ref($value) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 5 0 5
688 5 ▶ $newchildnode = $value if ref($value) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 5 5
689 } else {
690 0 return undef;
691 }
692  
693 5 ▶ if (ref($parentnode->{$childname}) eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'ARRAY') { } 5 0 5
elsif (ref $parentnode->{$childname} eq 'HASH') { } 0 0 0
694 5 my @childpositions;
695 5 ▶ if ((defined $childpos) && ($childpos >= 1) && ($childpos <= @{$parentnode->{$childname}})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}) { } 5 0 5
elsif (not defined $childpos) { } 0 0 0
Condition33%2/6
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
!ll&&!rl&&r
005
defined $childpos and $childpos >= 1
!ll&&!rl&&r
005
MC/DC0%0/3
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
defined $childpos $childpos >= 1 $childpos <= @{$parentnode->{$childname};}
Truth table25%1/4
A and B and C
A= defined $childposB= $childpos >= 1C= $childpos <= @{$parentnode->{$childname};}
ABCresult
0XX0
10X0
1100
1111
696 5 push (@childpositions,$childpos);
697 } elsif (!defined $childpos) {
698 0 ▶ for (my $i=1; $i <= @{$parentnode->{$childname}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= @{$parentnode->{$childname};}) 0 0 0
699 0 push (@childpositions,$i);
700 }
701 } else {
702 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
703 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
704 0 return undef;
705 }
706 5 foreach my $tchildpos (@childpositions) {
707 5 ▶ if (ref($parentnode->{$childname}->[($tchildpos - 1)]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$tchildpos - 1] eq 'HASH') { } 5 0 5
elsif (not ref $parentnode->{$childname}[$tchildpos - 1]) { } 0 0 0
708 5 ▶ if (defined $stringname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 5 5
709 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}->[($tchildpos - 1)], { $stringname => $newchildnode->[0]->{$stringname} }, $action);
710 } else {
711 5 $result += $nodeMergeActionSingle->($parentnode->{$childname}->[($tchildpos - 1)], $newchildnode->[0], $action);
712 }
713 } elsif (!ref($parentnode->{$childname}->[($tchildpos - 1)])) {
714 0 ▶ if ((defined $stringname) && ($isnodetype->($stringname, "text"))) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname and &$isnodetype($stringname, 'text')) { } 0 0 0
Condition0%0/3
defined $stringname and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stringname and &$isnodetype($stringname, "text")
defined $stringname &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= defined $stringnameB= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
715 # append to #text
716 0 ▶ if ($action eq "replace") {
Branch: 4 branches
BranchTrueFalseTotal
if ($action eq 'replace') { } 0 0 0
elsif ($action eq 'append') { } 0 0 0
elsif ($action eq 'add') { } 0 0 0
elsif ($action eq 'delete') { } 0 0 0
717 0 $parentnode->{$childname}->[($tchildpos - 1)] = $newchildnode->[0]->{$stringname};
718 0 $result++;
719 } elsif ($action eq "append") {
720 0 $parentnode->{$childname}->[($tchildpos - 1)] .= $newchildnode->[0]->{$stringname};
721 0 $result++;
722 } elsif ($action eq "add") {
723 0 ▶ if ($parentnode->{$childname}->[($tchildpos - 1)] !~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parentnode->{$childname}[$tchildpos - 1] =~ /\w+/) 0 0 0
724 0 $parentnode->{$childname}->[($tchildpos - 1)] = $newchildnode->[0]->{$stringname};
725 0 $result++;
726 }
727 } elsif ($action eq "delete") {
728 0 $parentnode->{$childname}->[($tchildpos - 1)] = undef;
729 0 $result++;
730 }
731 } else {
732 0 ▶ if ((defined $parentnode->{$childname}->[($tchildpos - 1)]) && ($parentnode->{$childname}->[($tchildpos - 1)] =~ /\w+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parentnode->{$childname}[$tchildpos - 1] and $parentnode->{$childname}[$tchildpos - 1] =~ /\w+/) { } 0 0 0
Condition0%0/3
defined $parentnode->{$childname}[$tchildpos - 1] and $parentnode->{$childname}[$tchildpos - 1] =~ /\w+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parentnode->{$childname}[$tchildpos - 1] and $parentnode->{$childname}[$tchildpos - 1] =~ /\w+/
defined $parentnode->{$childname}[$tchildpos - 1] $parentnode->{$childname}[$tchildpos - 1] =~ /\w+/
Truth table0%0/3
A and B
A= defined $parentnode->{$childname}[$tchildpos - 1]B= $parentnode->{$childname}[$tchildpos - 1] =~ /\w+/
ABresult
0X0
100
111
733 0 $parentnode->{$childname}->[($tchildpos - 1)] = { $xml_text_id => $parentnode->{$childname}->[($tchildpos - 1)] };
734 } else {
735 0 $parentnode->{$childname}->[($tchildpos - 1)] = {};
736 }
737 0 ▶ if (defined $stringname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
738 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}->[($tchildpos - 1)], { $stringname => $newchildnode->[0]->{$stringname} }, $action);
739 } else {
740 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}->[($tchildpos - 1)], $newchildnode->[0], $action);
741 }
742 }
743 }
744 }
745 } elsif (ref($parentnode->{$childname}) eq "HASH") {
746 0 ▶ if ( ((defined $childpos) && ($childpos == 1)) || (!defined $childpos) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $childpos and $childpos == 1 or not defined $childpos) { } 0 0 0
Condition0%0/6
defined $childpos and $childpos == 1 or not defined $childpos
l!l&&r!l&&!r
000
defined $childpos and $childpos == 1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $childpos and $childpos == 1 or not defined $childpos
defined $childpos $childpos == 1 not defined $childpos
Truth table0%0/5
A and B or not(C)
A= defined $childposB= $childpos == 1C= not defined $childpos
ABCresult
11X1
0X11
1011
0X00
1000
747 0 ▶ if (defined $stringname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
748 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}, { $stringname => $newchildnode->[0]->{$stringname} }, $action);
749 } else {
750 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}, $newchildnode->[0], $action);
751 }
752 } else {
753 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
754 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
755 0 return undef;
756 }
757 } else {
758 0 ▶ if ( ((defined $childpos) && ($childpos == 1)) || (!defined $childpos) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $childpos and $childpos == 1 or not defined $childpos) { } 0 0 0
Condition0%0/6
defined $childpos and $childpos == 1 or not defined $childpos
l!l&&r!l&&!r
000
defined $childpos and $childpos == 1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $childpos and $childpos == 1 or not defined $childpos
defined $childpos $childpos == 1 not defined $childpos
Truth table0%0/5
A and B or not(C)
A= defined $childposB= $childpos == 1C= not defined $childpos
ABCresult
11X1
0X11
1011
0X00
1000
759 0 ▶ if ((defined $stringname) && ($isnodetype->($stringname, "text"))) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname and &$isnodetype($stringname, 'text')) { } 0 0 0
Condition0%0/3
defined $stringname and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stringname and &$isnodetype($stringname, "text")
defined $stringname &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= defined $stringnameB= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
760 # append to #text
761 0 ▶ if ($action eq "replace") {
Branch: 4 branches
BranchTrueFalseTotal
if ($action eq 'replace') { } 0 0 0
elsif ($action eq 'append') { } 0 0 0
elsif ($action eq 'add') { } 0 0 0
elsif ($action eq 'delete') { } 0 0 0
762 0 $parentnode->{$childname} = $newchildnode->[0]->{$stringname};
763 0 $result++;
764 } elsif ($action eq "append") {
765 0 $parentnode->{$childname} .= $newchildnode->[0]->{$stringname};
766 0 $result++;
767 } elsif ($action eq "add") {
768 0 ▶ if ($parentnode->{$childname} !~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parentnode->{$childname} =~ /\w+/) 0 0 0
769 0 $parentnode->{$childname} = $newchildnode->[0]->{$stringname};
770 0 $result++;
771 }
772 } elsif ($action eq "delete") {
773 0 $parentnode->{$childname} = undef;
774 0 $result++;
775 }
776 } else {
777 0 ▶ if ((defined $parentnode->{$childname}) && ($parentnode->{$childname} =~ /\w+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parentnode->{$childname} and $parentnode->{$childname} =~ /\w+/) { } 0 0 0
Condition0%0/3
defined $parentnode->{$childname} and $parentnode->{$childname} =~ /\w+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parentnode->{$childname} and $parentnode->{$childname} =~ /\w+/
defined $parentnode->{$childname} $parentnode->{$childname} =~ /\w+/
Truth table0%0/3
A and B
A= defined $parentnode->{$childname}B= $parentnode->{$childname} =~ /\w+/
ABresult
0X0
100
111
778 0 $parentnode->{$childname} = { $xml_text_id => $parentnode->{$childname} };
779 } else {
780 0 $parentnode->{$childname} = {};
781 }
782 0 ▶ if (defined $stringname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
783 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}, { $stringname => $newchildnode->[0]->{$stringname} }, $action);
784 } else {
785 0 $result += $nodeMergeActionSingle->($parentnode->{$childname}, $newchildnode->[0], $action);
786 }
787 }
788 } else {
789 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
790 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
791 0 return undef;
792 }
793 }
794 }
795 5 return $result;
796 10 };
797  
798 10 ▶ my $nodeInsert = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
799 1 ▶ $nodeInsert = sub (@) {
Subroutine __ANON__: called CC=22 SCAR=50.6
800 1 my $parentnode = shift; # ref - must be HASH ref, or ARRAY if inserting to multiple parents
801 1 my $childname = shift; # ref->ref # insert a new node with this child name | or insert $stringname to this existing node
802 1 my $childpos = shift; # ref->ref->[#] - can be undef # insert the new node at this position, undef to append | or insert $stringname to existing node at this position
803 1 my $stringname = shift; # ref->ref->[#]->name - can be undef # insert this $stringname with $value to the child node | or append $value if $stringname exists
804 1 my $value = shift; # ref->ref->[#]->name = $value # the string value for $stringname if defined | or the value for the node named $childname
805 1 my $result = 0;
806  
807 1 ▶ if (!ref($parentnode)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode) { } 0 1 1
elsif (ref $parentnode eq 'ARRAY') { } 0 1 1
elsif (ref $parentnode eq 'HASH') { } 1 0 1
808 0 croak "Cannot insert a child node to a non referencing parent node.";
809 0 return undef;
810 } elsif (ref($parentnode) eq "ARRAY") {
811 0 ▶ if (@{$parentnode} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parentnode;} == 0) 0 0 0
812 0 push (@{$parentnode}, {});
813 }
814 0 foreach my $single_parentnode (@{$parentnode}) {
815 0 my $newresult = $nodeInsert->($single_parentnode,$childname,$childpos,$stringname,$value);
816 0 $result += $newresult;
817 }
818 } elsif (ref($parentnode) eq "HASH") {
819 # In every case here, we are inserting a new child node
820 1 my $newchildnode;
821 1 ▶ if ((!ref($value)) && (defined $value) && (defined $stringname)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $value and defined $value and defined $stringname) { } 0 1 1
elsif (not ref $value || defined $stringname) { } 0 1 1
elsif (ref $value) { } 1 0 1
Condition33%2/6
not ref $value and defined $value and defined $stringname
!ll&&!rl&&r
100
not ref $value and defined $value
!ll&&!rl&&r
100
MC/DC0%0/3
not ref $value and defined $value and defined $stringname
not ref $value defined $value defined $stringname
Truth table25%1/4
not(A) and B and C
A= not ref $valueB= defined $valueC= defined $stringname
ABCresult
0XX0
10X0
1100
1111
822 0 $newchildnode = [{ $stringname => $value }];
823 ▶ } elsif ((!ref($value)) && (!defined $stringname)) {
Condition33%1/3
ref $value || defined $stringname
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $value || defined $stringname
ref $value defined $stringname
Truth table33%1/3
A || B
A= ref $valueB= defined $stringname
ABresult
1X1
011
000
824 0 $newchildnode = [{ $xml_text_id => $value }];
825 } elsif (ref($value)) {
826 1 ▶ $newchildnode = [ $value ] if ref($value) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 1 0 1
827 1 ▶ $newchildnode = $value if ref($value) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 1 1
828 } else {
829 0 return undef;
830 }
831  
832 1 ▶ if (!ref($parentnode->{$childname})) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode->{$childname}) { } 0 1 1
elsif (ref $parentnode->{$childname} eq 'HASH') { } 0 1 1
elsif (ref $parentnode->{$childname} eq 'ARRAY') { } 1 0 1
833 0 ▶ if ($parentnode->{$childname} =~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parentnode->{$childname} =~ /\w+/) { } 0 0 0
834 0 my $currentchildnode = { $xml_text_id => $parentnode->{$childname} };
835 0 ▶ if ($childpos == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childpos == 1) { } 0 0 0
836 0 $parentnode->{$childname} = [ @{$newchildnode}, $currentchildnode ];
837 0 $result += @{$newchildnode};
838 } else {
839 0 $parentnode->{$childname} = [ $currentchildnode, @{$newchildnode} ];
840 0 $result += @{$newchildnode};
841 }
842 } else {
843 0 $parentnode->{$childname} = $newchildnode;
844 0 $result += @{$newchildnode};
845 }
846 } elsif (ref($parentnode->{$childname}) eq "HASH") {
847 0 ▶ if ($childpos == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childpos == 1) { } 0 0 0
848 0 push (@{$newchildnode}, $parentnode->{$childname});
849 0 $result += @{$newchildnode};
850 } else {
851 0 unshift (@{$newchildnode}, $parentnode->{$childname});
852 0 $result += @{$newchildnode};
853 }
854 0 $parentnode->{$childname} = $newchildnode
855 } elsif (ref($parentnode->{$childname}) eq "ARRAY") {
856 1 my $size = @{$parentnode->{$childname}};
857 1 ▶ if (($childpos >= 1) && ($childpos <= $size)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childpos >= 1 and $childpos <= $size) { } 1 0 1
Condition33%1/3
$childpos >= 1 and $childpos <= $size
!ll&&!rl&&r
001
MC/DC0%0/2
$childpos >= 1 and $childpos <= $size
$childpos >= 1 $childpos <= $size
Truth table33%1/3
A and B
A= $childpos >= 1B= $childpos <= $size
ABresult
0X0
100
111
858 1 splice(@{$parentnode->{$childname}},($childpos - 1), 0, @{$newchildnode});
859 1 $result += @{$newchildnode};
860 } else {
861 0 push(@{$parentnode->{$childname}}, @{$newchildnode});
862 0 $result += @{$newchildnode};
863 }
864 }
865 }
866 1 return $result;
867 10 };
868  
869 10 ▶ my $nodeReplace = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
870 4 ▶ $nodeReplace = sub (@) {
Subroutine __ANON__: called CC=39 SCAR=65.5
871 4 my $parentnode = shift; # ref - must be HASH ref, or ARRAY if replacing to multiple parents
872 4 my $childname = shift; # ref->ref # replace the node with this child name | or replace $stringname of existing child node
873 4 my $childpos = shift; # ref->ref->[#] - can be undef # replace the node at this position, undef to replace all | or replace $stringname of existing child node at this position
874 4 my $stringname = shift; # ref->ref->[#]->name - can be undef # replace this $stringname of the child node
875 4 my $value = shift;
876 4 my $result = 0;
877 # print Dumper({ parentnode => $parentnode, childname => $childname, childpos => $childpos, stringname => $stringname, value => $value });
878  
879 4 ▶ if (!ref($parentnode)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode) { } 0 4 4
elsif (ref $parentnode eq 'ARRAY') { } 0 4 4
elsif (ref $parentnode eq 'HASH') { } 4 0 4
880 0 croak "Cannot replace a child node to a non referencing parent node.";
881 0 return undef;
882 } elsif (ref($parentnode) eq "ARRAY") {
883 0 ▶ if (@{$parentnode} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parentnode;} == 0) 0 0 0
884 0 $parentnode = [{}];
885 }
886 0 foreach my $single_parentnode (@{$parentnode}) {
887 0 my $newresult = $nodeReplace->($single_parentnode,$childname,$childpos,$stringname,$value);
888 0 $result += $newresult;
889 }
890 } elsif (ref($parentnode) eq "HASH") {
891 # In every case (but for replacing $stringname), we are replacing a new child node, having deleted any existing at the same path
892 4 my $newchildnode;
893 4 ▶ if ((!ref($value)) && (defined $value) && (defined $stringname)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $value and defined $value and defined $stringname) { } 0 4 4
elsif (not ref $value || defined $stringname) { } 0 4 4
Condition33%2/6
not ref $value and defined $value and defined $stringname
!ll&&!rl&&r
400
not ref $value and defined $value
!ll&&!rl&&r
400
MC/DC0%0/3
not ref $value and defined $value and defined $stringname
not ref $value defined $value defined $stringname
Truth table25%1/4
not(A) and B and C
A= not ref $valueB= defined $valueC= defined $stringname
ABCresult
0XX0
10X0
1100
1111
894 0 $newchildnode = [{ $stringname => $value }];
895 ▶ } elsif ((!ref($value)) && (!defined $stringname)) {
Condition33%1/3
ref $value || defined $stringname
l!l&&r!l&&!r
400
MC/DC0%0/2
ref $value || defined $stringname
ref $value defined $stringname
Truth table33%1/3
A || B
A= ref $valueB= defined $stringname
ABresult
1X1
011
000
896 0 $newchildnode = [{ $xml_text_id => $value }];
897 } else {
898 4 ▶ $newchildnode = [ $value ] if ref($value) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 4 0 4
899 4 ▶ $newchildnode = $value if ref($value) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 4 4
900 }
901  
902 4 ▶ if (ref($parentnode->{$childname}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'ARRAY') { } 4 0 4
903 4 ▶ if ((defined $childpos) && ($childpos >= 1) && ($childpos <= @{$parentnode->{$childname}})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}) { } 4 0 4
elsif (not defined $childpos) { } 0 0 0
Condition33%2/6
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
!ll&&!rl&&r
004
defined $childpos and $childpos >= 1
!ll&&!rl&&r
004
MC/DC0%0/3
defined $childpos and $childpos >= 1 and $childpos <= @{$parentnode->{$childname};}
defined $childpos $childpos >= 1 $childpos <= @{$parentnode->{$childname};}
Truth table25%1/4
A and B and C
A= defined $childposB= $childpos >= 1C= $childpos <= @{$parentnode->{$childname};}
ABCresult
0XX0
10X0
1100
1111
904 4 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 4 4
905 # Node could just be CDATA (#text) and not HASH
906 0 ▶ if (ref($parentnode->{$childname}->[($childpos - 1)]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$childpos - 1] eq 'HASH') { } 0 0 0
elsif ($parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, 'text')) { } 0 0 0
907 0 $parentnode->{$childname}->[($childpos - 1)]->{$stringname} = $newchildnode->[0]->{$stringname};
908 0 $result++;
909 ▶ } elsif (($parentnode->{$childname}->[($childpos - 1)] =~ /\w+/) && ($isnodetype->($stringname, "text"))) {
Condition0%0/3
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, "text")
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= $parentnode->{$childname}[$childpos - 1] =~ /\w+/B= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
910 0 $parentnode->{$childname}->[($childpos - 1)] = $newchildnode->[0]->{$stringname};
911 0 $result++;
912 }
913 } else {
914 4 splice(@{$parentnode->{$childname}},($childpos - 1), 1, @{$newchildnode});
915 4 $result += @{$newchildnode};
916 }
917 } elsif (!defined $childpos) {
918 # If not $childpos, then all items of node are affected
919 0 my $i = 0;
920 0 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
921 0 ▶ while ($i < @{$parentnode->{$childname}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$parentnode->{$childname};}) 0 0 0
922 0 ▶ print "-replace array $childname $i\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::TreePP::Editor::DEBUG 0 0 0
923 # Node could just be CDATA (#text) and not HASH
924 0 ▶ if (ref($parentnode->{$childname}->[$i]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$i] eq 'HASH') { } 0 0 0
elsif ($parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, 'text')) { } 0 0 0
925 0 $parentnode->{$childname}->[$i]->{$stringname} = $newchildnode->[0]->{$stringname};
926 0 $result++;
927 ▶ } elsif (($parentnode->{$childname}->[$i] =~ /\w+/) && ($isnodetype->($stringname, "text"))) {
Condition0%0/3
$parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
$parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, "text")
$parentnode->{$childname}[$i] =~ /\w+/ &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= $parentnode->{$childname}[$i] =~ /\w+/B= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
928 0 $parentnode->{$childname}->[$i] = $newchildnode->[0]->{$stringname};
929 0 $result++;
930 }
931 0 $i++;
932 }
933 } else {
934 0 ▶ print "-replace ALL $childname $i\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::TreePP::Editor::DEBUG 0 0 0
935 0 $parentnode->{$childname} = $newchildnode;
936 0 $result++;
937 }
938 } else {
939 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
940 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
941 0 return undef;
942 }
943 } else {
944 0 ▶ if ((!defined $childpos) || ($childpos == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $childpos or $childpos == 1) { } 0 0 0
Condition0%0/3
not defined $childpos or $childpos == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $childpos or $childpos == 1
not defined $childpos $childpos == 1
Truth table0%0/3
not(A) or B
A= not defined $childposB= $childpos == 1
ABresult
1X1
011
000
945 0 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
946 # print Dumper( { parentnode => $parentnode, childname => $childname, stringname => $stringname, newchildname => $newchildnode } );
947 0 ▶ if (ref($parentnode->{$childname}) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'HASH') { } 0 0 0
elsif ($parentnode->{$childname} =~ /\w+/ and &$isnodetype($stringname, 'text')) { } 0 0 0
948 0 $parentnode->{$childname}->{$stringname} = $newchildnode->[0]->{$stringname};
949 0 $result++;
950 ▶ } elsif (($parentnode->{$childname} =~ /\w+/) && ($isnodetype->($stringname, "text"))) {
Condition0%0/3
$parentnode->{$childname} =~ /\w+/ and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
$parentnode->{$childname} =~ /\w+/ and &$isnodetype($stringname, "text")
$parentnode->{$childname} =~ /\w+/ &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= $parentnode->{$childname} =~ /\w+/B= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
951 0 $parentnode->{$childname} = $newchildnode->[0]->{$stringname};
952 0 $result++;
953 }
954 } else {
955 0 $parentnode->{$childname} = $newchildnode;
956 0 $result++;
957 }
958 } else {
959 0 ▶ croak "Cannot replace child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
960 0 ▶ croak "Cannot replace child node items, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
961 0 return undef;
962 }
963 }
964 }
965 4 return $result;
966 10 };
967  
968 10 ▶ my $nodeDelete = sub (@) {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
969 4 ▶ $nodeDelete = sub (@) {
Subroutine __ANON__: called CC=27 SCAR=59.7
970 4 my $parentnode = shift; # ref - must be HASH ref, or ARRAY if replacing to multiple parents
971 4 my $childname = shift; # ref->[#]->ref # delete the node with this child name | or delete $stringname of existing child node
972 4 my $childpos = shift; # ref->[#]->ref->[#] - can be undef # delete the node at this position, undef to delete all | or delete $stringname of existing child node at this position
973 4 my $stringname = shift; # ref->[#]->ref->[#]->name - can be undef # delete this $stringname of the child node
974 4 my $result = 0;
975  
976 4 ▶ if (!ref($parentnode)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $parentnode) { } 0 4 4
elsif (ref $parentnode eq 'ARRAY') { } 0 4 4
elsif (ref $parentnode eq 'HASH') { } 4 0 4
977 0 croak "Cannot delete a child node to a non referencing parent node.";
978 0 return undef;
979 } elsif (ref($parentnode) eq "ARRAY") {
980 0 ▶ if (@{$parentnode} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parentnode;} == 0) 0 0 0
981 0 $parentnode = [{}];
982 }
983 0 foreach my $single_parentnode (@{$parentnode}) {
984 0 my $newresult = $nodeDelete->($single_parentnode,$childname,$childpos,$stringname);
985 0 $result += $newresult;
986 }
987 } elsif (ref($parentnode) eq "HASH") {
988 4 ▶ if (ref($parentnode->{$childname}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parentnode->{$childname} eq 'ARRAY') { } 4 0 4
989 4 ▶ if ((defined $childpos) && ($childpos >= 1) && (($childpos - 1) <= @{$parentnode->{$childname}})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $childpos and $childpos >= 1 and $childpos - 1 <= @{$parentnode->{$childname};}) { } 4 0 4
elsif (not defined $childpos) { } 0 0 0
Condition33%2/6
defined $childpos and $childpos >= 1 and $childpos - 1 <= @{$parentnode->{$childname};}
!ll&&!rl&&r
004
defined $childpos and $childpos >= 1
!ll&&!rl&&r
004
MC/DC0%0/3
defined $childpos and $childpos >= 1 and $childpos - 1 <= @{$parentnode->{$childname};}
defined $childpos $childpos >= 1 $childpos - 1 <= @{$parentnode->{$childname};}
Truth table25%1/4
A and B and C
A= defined $childposB= $childpos >= 1C= $childpos - 1 <= @{$parentnode->{$childname};}
ABCresult
0XX0
10X0
1100
1111
990 4 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 4 4
991 0 ▶ if (ref($parentnode->{$childname}->[($childpos - 1)]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$childpos - 1] eq 'HASH') { } 0 0 0
elsif ($parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, 'text')) { } 0 0 0
992 0 delete $parentnode->{$childname}->[($childpos - 1)]->{$stringname};
993 0 $result++;
994 ▶ } elsif (($parentnode->{$childname}->[($childpos - 1)] =~ /\w+/) && ($isnodetype->($stringname, "text"))) {
Condition0%0/3
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ and &$isnodetype($stringname, "text")
$parentnode->{$childname}[$childpos - 1] =~ /\w+/ &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= $parentnode->{$childname}[$childpos - 1] =~ /\w+/B= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
995 0 $parentnode->{$childname}->[($childpos - 1)] = undef;
996 0 $result++;
997 }
998 } else {
999 #delete $parentnode->{$childname}->[($childpos - 1)];
1000 4 splice (@{$parentnode->{$childname}},($childpos - 1),1);
1001 4 $result++;
1002 }
1003 } elsif (!defined $childpos) {
1004 0 my $i = 0;
1005 0 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
1006 0 ▶ while ($i < @{$parentnode->{$childname}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$parentnode->{$childname};}) 0 0 0
1007 0 ▶ if (ref($parentnode->{$childname}->[$i]) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parentnode->{$childname}[$i] eq 'HASH') { } 0 0 0
elsif ($parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, 'text')) { } 0 0 0
1008 0 delete $parentnode->{$childname}->[$i]->{$stringname};
1009 0 $result++;
1010 ▶ } elsif (($parentnode->{$childname}->[$i] =~ /\w+/) && ($isnodetype->($stringname, "text"))) {
Condition0%0/3
$parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, "text")
!ll&&!rl&&r
000
MC/DC0%0/2
$parentnode->{$childname}[$i] =~ /\w+/ and &$isnodetype($stringname, "text")
$parentnode->{$childname}[$i] =~ /\w+/ &$isnodetype($stringname, "text")
Truth table0%0/3
A and B
A= $parentnode->{$childname}[$i] =~ /\w+/B= &$isnodetype($stringname, "text")
ABresult
0X0
100
111
1011 0 $parentnode->{$childname}->[$i] = undef;
1012 0 $result++;
1013 }
1014 0 $i++;
1015 }
1016 } else {
1017 0 delete $parentnode->{$childname};
1018 0 $result++;
1019 }
1020 } else {
1021 0 my $num = @{$parentnode->{$childname}};
1022 0 ▶ croak "Cannot delete child node $childname at position $childpos when there is $num." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
1023 0 ▶ croak "Cannot delete from child node $childname, none exists at position $childpos when there is $num." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
1024 0 return undef;
1025 }
1026 } else {
1027 0 ▶ if ((!defined $childpos) || ($childpos == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $childpos or $childpos == 1) { } 0 0 0
Condition0%0/3
not defined $childpos or $childpos == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $childpos or $childpos == 1
not defined $childpos $childpos == 1
Truth table0%0/3
not(A) or B
A= not defined $childposB= $childpos == 1
ABresult
1X1
011
000
1028 0 ▶ if (defined $stringname) { # Make sure we account for { node => <CDATA> } opposed to { node => { #text => <CDATA> } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stringname) { } 0 0 0
1029 0 delete $parentnode->{$childname}->{$stringname};
1030 } else {
1031 0 delete $parentnode->{$childname};
1032 }
1033 } else {
1034 0 ▶ croak "Cannot delete child node, none exists at position $childpos." if !defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stringname 0 0 0
1035 0 ▶ croak "Cannot delete from child node, none exists at position $childpos." if defined $stringname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stringname 0 0 0
1036 0 return undef;
1037 }
1038 }
1039 }
1040 4 return $result;
1041 10 };
1042  
1043 # This can be the function $mod->($parent_nodes,insert|replace|delete|mergeadd|mergereplace|mergedelete|mergeappend,$child_path,string,$value);
1044 14 ▶ my $mod = sub (@) {
Subroutine __ANON__: called CC=43 SCAR=57.0
1045 14 my $parent_nodes = shift; # @{$parent_nodes}
1046 14 my $action = shift; # insert|replace|delete|mergeadd|mergereplace|mergedelete|mergeappend
1047 14 my $child_path = shift; # XMLPath
1048 14 my $string_element = shift; # @attrname | #text
1049 14 my $value = shift; # "value"
1050 14 my $numAffected = 0;
1051  
1052 14 ▶ if (($action ne "insert") && ($action ne "replace") && ($action ne "delete")
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd" and $action ne "mergeappend" and $action ne "mergereplace" and $action ne "mergedelete") 0 14 14
Condition94%17/18
$action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd" and $action ne "mergeappend" and $action ne "mergereplace" and $action ne "mergedelete"
!ll&&!rl&&r
1310
$action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd" and $action ne "mergeappend" and $action ne "mergereplace"
!ll&&!rl&&r
1211
$action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd" and $action ne "mergeappend"
!ll&&!rl&&r
1022
$action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd"
!ll&&!rl&&r
914
$action ne "insert" and $action ne "replace" and $action ne "delete"
!ll&&!rl&&r
545
$action ne "insert" and $action ne "replace"
!ll&&!rl&&r
149
MC/DC0%0/7
$action ne "insert" and $action ne "replace" and $action ne "delete" and $action ne "mergeadd" and $action ne "mergeappend" and $action ne "mergereplace" and $action ne "mergedelete"
$action ne "insert" $action ne "replace" $action ne "delete" $action ne "mergeadd" $action ne "mergeappend" $action ne "mergereplace" $action ne "mergedelete"
Truth table87%7/8
A and B and C and D and E and F and G
A= $action ne "insert"B= $action ne "replace"C= $action ne "delete"D= $action ne "mergeadd"E= $action ne "mergeappend"F= $action ne "mergereplace"G= $action ne "mergedelete"
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
1053 && ($action ne "mergeadd") && ($action ne "mergeappend") && ($action ne "mergereplace") && ($action ne "mergedelete") ) {
1054 0 croak "Modify only supports insert, replace, merge or delete";
1055 }
1056  
1057 # Extract positional
1058 14 my ($positionFilter,$position);
1059 14 ▶ if ($child_path->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_path->[1]) 14 0 14
1060 14 ▶ if ($child_path->[1]->[0]->[0] =~ /^\d*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_path->[1][0][0] =~ /^\d*$/) 14 0 14
1061 14 $positionFilter = shift @{$child_path->[1]};
1062 14 ▶ $position = $positionFilter->[0] || undef;
Condition50%1/2
$positionFilter->[0] || undef
l!l
140
MC/DC0%0/1
$positionFilter->[0] || undef
$positionFilter->[0]
Truth table50%1/2
A
A= $positionFilter->[0]
Aresult
11
00
1063 }
1064 }
1065 14 foreach my $xref (@{$parent_nodes}) {
1066 14 ▶ if (ref($xref) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $xref eq 'HASH') { } 14 0 14
elsif (ref $xref eq 'ARRAY') { } 0 0 0
1067  
1068 14 my @positions;
1069 0 ▶ if ((!defined $position) && (ref($xref->{ $child_path->[0] }) eq "ARRAY") && (defined $child_path->[1]) && (@{$child_path->[1]} > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $position and ref $$xref{$child_path->[0]} eq 'ARRAY' and defined $child_path->[1] and @{$child_path->[1];} > 0) { } 0 14 14
Condition33%3/9
not defined $position and ref $$xref{$child_path->[0]} eq "ARRAY" and defined $child_path->[1] and @{$child_path->[1];} > 0
!ll&&!rl&&r
1400
not defined $position and ref $$xref{$child_path->[0]} eq "ARRAY" and defined $child_path->[1]
!ll&&!rl&&r
1400
not defined $position and ref $$xref{$child_path->[0]} eq "ARRAY"
!ll&&!rl&&r
1400
MC/DC0%0/4
not defined $position and ref $$xref{$child_path->[0]} eq "ARRAY" and defined $child_path->[1] and @{$child_path->[1];} > 0
not defined $position ref $$xref{$child_path->[0]} eq "ARRAY" defined $child_path->[1] @{$child_path->[1];} > 0
Truth table20%1/5
not(A) and B and C and D
A= not defined $positionB= ref $$xref{$child_path->[0]} eq "ARRAY"C= defined $child_path->[1]D= @{$child_path->[1];} > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1070 0 my $ipos = 0;
1071 0 ▶ while ($xref->{ $child_path->[0] }->[$ipos]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$xref{$child_path->[0]}[$ipos]) 0 0 0
1072 0 ▶ if ( my $pass = $tppx->filterXMLDoc($xref->{ $child_path->[0] }->[$ipos], [[ ".", $child_path->[1] ]]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pass = $tppx->filterXMLDoc($$xref{$child_path->[0]}[$ipos], [[".", $child_path->[1]]])) 0 0 0
1073 0 push( @positions, ($ipos +1) );
1074 }
1075 0 $ipos++;
1076 }
1077 } else {
1078 14 push (@positions,$position);
1079 }
1080  
1081 14 foreach my $pos (@positions) {
1082 14 ▶ $numAffected += $nodeInsert->($xref,$child_path->[0],$pos,$string_element,$value) if $action eq "insert";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "insert" 1 13 14
1083 14 ▶ $numAffected += $nodeReplace->($xref,$child_path->[0],$pos,$string_element,$value) if $action eq "replace";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "replace" 4 10 14
1084 14 ▶ $numAffected += $nodeDelete->($xref,$child_path->[0],$pos,$string_element) if $action eq "delete";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "delete" 4 10 14
1085 14 ▶ $numAffected += $nodeMergeAction->($xref,$child_path->[0],$pos,$string_element,$value, mergetype => "mergeadd" ) if $action eq "mergeadd";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergeadd" 1 13 14
1086 14 ▶ $numAffected += $nodeMergeAction->($xref,$child_path->[0],$pos,$string_element,$value, mergetype => "mergeappend" ) if $action eq "mergeappend";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergeappend" 2 12 14
1087 14 ▶ $numAffected += $nodeMergeAction->($xref,$child_path->[0],$pos,$string_element,$value, mergetype => "mergereplace" ) if $action eq "mergereplace";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergereplace" 1 13 14
1088 14 ▶ $numAffected += $nodeMergeAction->($xref,$child_path->[0],$pos,$string_element,$value, mergetype => "mergedelete" ) if $action eq "mergedelete";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergedelete" 1 13 14
1089 }
1090  
1091 } elsif (ref($xref) eq "ARRAY") {
1092  
1093 0 foreach my $e (@$xref) {
1094 0 my @positions;
1095 0 ▶ if ((!defined $position) && (ref($e->{ $child_path->[0] }) eq "ARRAY") && (defined $child_path->[1]) && (@{$child_path->[1]} > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $position and ref $$e{$child_path->[0]} eq 'ARRAY' and defined $child_path->[1] and @{$child_path->[1];} > 0) { } 0 0 0
Condition0%0/9
not defined $position and ref $$e{$child_path->[0]} eq "ARRAY" and defined $child_path->[1] and @{$child_path->[1];} > 0
!ll&&!rl&&r
000
not defined $position and ref $$e{$child_path->[0]} eq "ARRAY" and defined $child_path->[1]
!ll&&!rl&&r
000
not defined $position and ref $$e{$child_path->[0]} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $position and ref $$e{$child_path->[0]} eq "ARRAY" and defined $child_path->[1] and @{$child_path->[1];} > 0
not defined $position ref $$e{$child_path->[0]} eq "ARRAY" defined $child_path->[1] @{$child_path->[1];} > 0
Truth table0%0/5
not(A) and B and C and D
A= not defined $positionB= ref $$e{$child_path->[0]} eq "ARRAY"C= defined $child_path->[1]D= @{$child_path->[1];} > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1096 0 my $ipos = 0;
1097 0 ▶ while ($e->{ $child_path->[0] }->[$ipos]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$e{$child_path->[0]}[$ipos]) 0 0 0
1098 0 ▶ if ( my $pass = $tppx->filterXMLDoc($e->{ $child_path->[0] }->[$ipos], [[ ".", $child_path->[1] ]]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pass = $tppx->filterXMLDoc($$e{$child_path->[0]}[$ipos], [[".", $child_path->[1]]])) 0 0 0
1099 0 push( @positions, ($ipos +1) );
1100 }
1101 0 $ipos++;
1102 }
1103 } else {
1104 0 push (@positions,$position);
1105 }
1106  
1107 0 foreach my $pos (@positions) {
1108 0 ▶ $numAffected += $nodeInsert->($e,$child_path->[0],$pos,$string_element,$value) if $action eq "insert";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "insert" 0 0 0
1109 0 ▶ $numAffected += $nodeReplace->($e,$child_path->[0],$pos,$string_element,$value) if $action eq "replace";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "replace" 0 0 0
1110 0 ▶ $numAffected += $nodeDelete->($e,$child_path->[0],$pos,$string_element) if $action eq "delete";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "delete" 0 0 0
1111 0 ▶ $numAffected += $nodeMergeAction->($e,$child_path->[0],$pos,$string_element,$value, mergetype => "mergeadd" ) if $action eq "mergeadd";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergeadd" 0 0 0
1112 0 ▶ $numAffected += $nodeMergeAction->($e,$child_path->[0],$pos,$string_element,$value, mergetype => "mergeappend" ) if $action eq "mergeappend";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergeappend" 0 0 0
1113 0 ▶ $numAffected += $nodeMergeAction->($e,$child_path->[0],$pos,$string_element,$value, mergetype => "mergereplace" ) if $action eq "mergereplace";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergereplace" 0 0 0
1114 0 ▶ $numAffected += $nodeMergeAction->($e,$child_path->[0],$pos,$string_element,$value, mergetype => "mergedelete" ) if $action eq "mergedelete";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "mergedelete" 0 0 0
1115 }
1116 }
1117  
1118 }
1119 }
1120 14 return $numAffected;
1121 10 };
1122  
1123 #pp (\%options);
1124 10 my $resultmaps = $self->tppx->filterXMLDoc($xtree, $xmlpath, structure => "ParentMAP");
1125 #pp ({ xmldoc => $xtree, xmlpath => $xmlpath, options => \%options, map => $resultmaps });
1126 10 foreach my $parentmap (@{$resultmaps}) {
1127 10 foreach my $action (keys %options) {
1128 10 ▶ my $value = $options{$action} || undef;
Condition100%2/2
$options{$action} || undef
l!l
82
MC/DC100%1/1
$options{$action} || undef
$options{$action}
Truth table100%2/2
A
A= $options{$action}
Aresult
11
00
1129 10 ▶ if ($action eq "insert") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "insert") 1 9 10
1130 1 my $child = $parentmap->{'child'}->[0];
1131 1 my $child_path = [ $child->{'name'}, [[$child->{'position'}, undef]] ];
1132 1 $numAffected += $mod->([$parentmap->{'root'}],$action,$child_path,$child->{'target'},$value);
1133 1 next;
1134 }
1135 9 ▶ if ($action eq "delete") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "delete") 2 7 9
1136 2 foreach my $child (reverse @{$parentmap->{'child'}}) {
1137 4 my $tmp_value = eval(Dumper($value));
1138 4 my $child_path = [ $child->{'name'}, [[$child->{'position'}, undef]] ];
1139 4 $numAffected += $mod->([$parentmap->{'root'}],$action,$child_path,$child->{'target'},$tmp_value);
1140 }
1141 2 next;
1142 }
1143 7 foreach my $child (@{$parentmap->{'child'}}) {
1144 9 my $tmp_value = eval(Dumper($value));
1145 9 my $child_path = [ $child->{'name'}, [[$child->{'position'}, undef]] ];
1146 9 $numAffected += $mod->([$parentmap->{'root'}],$action,$child_path,$child->{'target'},$tmp_value);
1147 }
1148 }
1149 }
1150  
1151 10 return $numAffected;
1152  
1153 }
1154  
1155  
1156 #How do we execute an add() ?
1157 #
1158 #Add will first check to see if xmlpath exists
1159 #If the path does not exist, then the $value is insert()ed into the xmldoc at the path indicated:
1160 # and path is #text - create node if it does not already exist, set #text
1161 # and path is @attribute - create node if it does not already exist, set @attribute
1162 # and path is node, $value is CDATA - create node if it does not already exist, set #text
1163 # and path is node, $value is REF - create the node as $value
1164 #If the path does exist, then we must asssume the $value is to be merge()d:
1165 # and path is #text - FAILURE, #text already exists - use merge to add additional content, or replace to change it
1166 # and path is @attribute - FAILURE, attribute already exists - use replace to change it
1167 # and path is node - FAILURE, node already exists - use insert to add additional nodes, merge to update this one, replace to change this one
1168  
1169 =pod
1170  
1171 =head2 insert
1172  
1173 insert( XMLTree, XMLPath, $value )
1174  
1175 This is the same as modify( XMLTree, XMLPath, insert => $value )
1176  
1177 =cut
1178 0 ▶sub insert (@) {
Subroutine insert: not called CC=4 SCAR=30.0
Pod documented
1179 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1180 0 my $xtree = shift;
1181 0 my $path = shift;
1182 0 my $value = shift;
1183 0 ▶ return $self->modify( $xtree, $path, insert => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1184 0 return modify( $xtree, $path, insert => $value );
1185 }
1186  
1187 =pod
1188  
1189 =head2 mergeadd
1190  
1191 mergeadd( XMLTree, XMLPath, $value )
1192  
1193 This is the same as modify( XMLTree, XMLPath, mergeadd => $value )
1194  
1195 =cut
1196 0 ▶sub mergeadd (@) { # mergeAdd mergeReplace mergeAppend mergeDelete
Subroutine mergeadd: not called CC=4 SCAR=30.0
Pod documented
1197 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1198 0 my $xtree = shift;
1199 0 my $path = shift;
1200 0 my $value = shift;
1201 0 ▶ return $self->modify( $xtree, $path, mergeadd => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1202 0 return modify( $xtree, $path, mergeadd => $value );
1203 }
1204  
1205 =pod
1206  
1207 =head2 mergereplace
1208  
1209 mergereplace( XMLTree, XMLPath, $value )
1210  
1211 This is the same as modify( XMLTree, XMLPath, mergereplace => $value )
1212  
1213 =cut
1214 0 ▶sub mergereplace (@) { # mergeAdd mergeReplace mergeAppend mergeDelete
Subroutine mergereplace: not called CC=4 SCAR=30.0
Pod documented
1215 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1216 0 my $xtree = shift;
1217 0 my $path = shift;
1218 0 my $value = shift;
1219 0 ▶ return $self->modify( $xtree, $path, mergereplace => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1220 0 return modify( $xtree, $path, mergereplace => $value );
1221 }
1222  
1223 =pod
1224  
1225 =head2 mergeappend
1226  
1227 mergeappend( XMLTree, XMLPath, $value )
1228  
1229 This is the same as modify( XMLTree, XMLPath, mergeappend => $value )
1230  
1231 =cut
1232 0 ▶sub mergeappend (@) { # mergeAdd mergeReplace mergeAppend mergeDelete
Subroutine mergeappend: not called CC=4 SCAR=30.0
Pod documented
1233 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1234 0 my $xtree = shift;
1235 0 my $path = shift;
1236 0 my $value = shift;
1237 0 ▶ return $self->modify( $xtree, $path, mergeappend => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1238 0 return modify( $xtree, $path, mergeappend => $value );
1239 }
1240  
1241 =pod
1242  
1243 =head2 mergedelete
1244  
1245 mergedelete( XMLTree, XMLPath, $value )
1246  
1247 This is the same as modify( XMLTree, XMLPath, mergedelete => $value )
1248  
1249 =cut
1250 0 ▶sub mergedelete (@) { # mergeAdd mergeReplace mergeAppend mergeDelete
Subroutine mergedelete: not called CC=4 SCAR=30.0
Pod documented
1251 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1252 0 my $xtree = shift;
1253 0 my $path = shift;
1254 0 my $value = shift;
1255 0 ▶ return $self->modify( $xtree, $path, mergedelete => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1256 0 return modify( $xtree, $path, mergedelete => $value );
1257 }
1258  
1259 =pod
1260  
1261 =head2 replace
1262  
1263 replace( XMLTree, XMLPath, $value )
1264  
1265 This is the same as modify( XMLTree, XMLPath, replace => $value )
1266  
1267 =cut
1268 0 ▶sub replace (@) {
Subroutine replace: not called CC=4 SCAR=30.0
Pod documented
1269 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1270 0 my $xtree = shift;
1271 0 my $path = shift;
1272 0 my $value = shift;
1273 0 ▶ return $self->modify( $xtree, $path, replace => $value ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1274 0 return modify( $xtree, $path, replace => $value );
1275 }
1276  
1277 =pod
1278  
1279 =head2 delete
1280  
1281 delete( XMLTree, XMLPath )
1282  
1283 This is the same as modify( XMLTree, XMLPath, delete => undef )
1284  
1285 =cut
1286 0 ▶sub delete (@) {
Subroutine delete: not called CC=4 SCAR=30.0
Pod documented
1287 0 ▶ my $self = shift if ref($_[0]) eq $REF_NAME || undef;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef 0 0 0
Condition0%0/2
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
l!l
00
MC/DC0%0/1
ref $_[0] eq $XML::TreePP::Editor::REF_NAME or undef
ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Truth table0%0/2
A
A= ref $_[0] eq $XML::TreePP::Editor::REF_NAME
Aresult
11
00
1288 0 my $xtree = shift;
1289 0 my $path = shift;
1290 0 ▶ return $self->modify( $xtree, $path, delete => undef ) if defined $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
1291 0 return modify( $xtree, $path, delete => undef );
1292 }
1293  
1294  
1295 2 1;
1296 __END__
↑ Summary