MyXML/Object.pm

filter: Statementstmt 94.4% 187 / 198 Branchbran 83.3% 105 / 126 Conditioncond 83.3% 30 / 36 MC/DCmcdc 66.6% 14 / 21 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 12 totaltotal 85.9% 356 / 414 CC 84 SCAR 23.9
CC
84
Cov
89%
cmp_element
21.5
_apply_namespace_declarations
17.3
text
11.0
CRAP 10.9
« MyXML.pm ↑ Summary MyXML/Util.pm »
1 package XML::MyXML::Object;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use XML::MyXML::Util 'trim', 'strip_ns';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 our $VERSION = "1.09";
13  
14 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my $class = shift;
16 0 my $xml = shift;
17  
18 0 return bless XML::MyXML::xml_to_object($xml), $class;
19 }
20  
21 5 my $ch0 = chr(0);
22 50 ▶sub _string_unescape {
Subroutine _string_unescape: called CC=3 SCAR=11.0
23 50 my $string = shift;
24  
25 50 ▶ defined $string or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $string or return undef 33 17 50
26  
27 33 my $ret = eval "qq${ch0}$string${ch0}";
28 33 ▶ defined $ret or croak "Can't unescape this string: $string";
Branch: 1 branch
BranchTrueFalseTotal
defined $ret or croak("Can't unescape this string: $string") 33 0 33
29  
30 33 return $ret;
31 }
32  
33 77 ▶sub _parse_description {
Subroutine _parse_description: called CC=2 SCAR=6.9
34 77 my ($desc) = @_;
35  
36 77 my ($el_name, $el_ns, $attrs_str) = $desc =~ /
37 # start anchor
38 ^
39  
40 # element name
41 (
42 (?:
43 \\ \[
44 |
45 \\ \{
46 |
47 [^\[\{]
48 )*
49 )
50  
51 # element namespace
52 (?:
53 # opening curly bracket
54 \{
55  
56 # namespace name
57 ((?: \\ \} | [^\}] )*)
58  
59 # closing curly bracket
60 \}
61 )?
62  
63 # attributes string
64 (.*)
65  
66 # end anchor
67 \z
68 /x;
69  
70 77 my @attrs = $attrs_str =~ /
71 # opening square bracket
72 \[
73  
74 # attribute name
75 (
76 # attribute characters
77 (?: \\ \] | \\ \= | \\ \{ | [^\]\=\{] )+
78 )
79  
80 # optional namespace
81 (?:
82 # opening curly bracket
83 \{
84  
85 # namespace name
86 ((?: \\ \} | [^\}] )*)
87  
88 # closing curly bracket
89 \}
90 )?
91  
92 # value option
93 (?:
94 # equals sign
95 \=
96  
97 # value
98 (
99 (?: \\ \] | [^\]] )*
100 )
101 )?
102  
103 # closing square bracket
104 \]
105 /gx;
106  
107 77 my %attrs;
108 77 ▶ while (@attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attrs) 15 77 92
109 15 my ($attr_name, $attr_ns, $attr_value) = splice @attrs, 0, 3;
110 # $attr_value =~ s/^\"|\"\z//g if defined $attr_value;
111 15 $attrs{_string_unescape $attr_name} = {
112 ns => _string_unescape($attr_ns),
113 value => _string_unescape($attr_value),
114 };
115 }
116  
117 77 return ($el_name, $el_ns, \%attrs);
118 }
119  
120 155 ▶sub cmp_element {
Subroutine cmp_element: called CC=19 SCAR=30.7
Pod undocumented
121 155 my ($self, $desc) = @_;
122  
123 my ($el_name, $el_ns, $attrs) = ref $desc
124 155 ▶ ? @$desc{qw/ el_name el_ns attrs /}
Branch: 1 branch
BranchTrueFalseTotal
ref $desc ? : 143 12 155
125 : _parse_description($desc);
126  
127 # check element name
128 155 ▶ if (length $el_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $el_name) 147 8 155
129 147 ▶ if (! defined $el_ns) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $el_ns) { } 145 2 147
elsif (length $el_ns) { } 2 0 2
130 145 ▶ $self->{el_name} eq $el_name or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"el_name"} eq $el_name or return 0 105 40 145
131 } elsif (length $el_ns) {
132 2 ▶ $el_name !~ /\:/ or croak 'You can either have a ns requirement, or a ":" in your path segment';
Branch: 1 branch
BranchTrueFalseTotal
$el_name =~ /\:/ and croak("You can either have a ns requirement, or a \":\" in your path segment") 0 2 2
133 2 ▶ exists $self->{ns_data}{"$el_ns:"} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"ns_data"}{"${el_ns}:"} or return 0 2 0 2
134 2 ▶ strip_ns($self->{el_name}) eq $el_name or return 0;
Branch: 1 branch
BranchTrueFalseTotal
strip_ns($self->{"el_name"}) eq $el_name or return 0 2 0 2
135 } else {
136 # ! grep /\:\z/, keys %{ $self->{ns_data} } or return 0;
137 # $self->{el_name} eq $el_name or return 0;
138 0 croak 'empty ns in path segment';
139 }
140 }
141  
142 # check attributes
143 115 foreach my $attr_name (keys %$attrs) {
144 50 my ($attr_ns, $attr_value) = @{ $attrs->{$attr_name} }{qw/ ns value /};
145 50 ▶ if (! defined $attr_ns) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $attr_ns) { } 48 2 50
elsif (length $attr_ns) { } 2 0 2
146 48 my $actual_attr_value = $self->attr($attr_name);
147 48 ▶ defined $actual_attr_value or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $actual_attr_value or return 0 35 13 48
148 35 ▶ ! defined $attr_value or $attr_value eq $actual_attr_value or return 0;
Branch: 1 branch
BranchTrueFalseTotal
not defined $attr_value or $attr_value eq $actual_attr_value or return 0 16 19 35
Condition100%3/3
not defined $attr_value or $attr_value eq $actual_attr_value
l!l&&r!l&&!r
21419
MC/DC100%2/2
not defined $attr_value or $attr_value eq $actual_attr_value
not defined $attr_value $attr_value eq $actual_attr_value
Truth table100%3/3
not(A) or B
A= not defined $attr_valueB= $attr_value eq $actual_attr_value
ABresult
1X1
011
000
149 } elsif (length $attr_ns) {
150 2 ▶ $attr_name !~ /\:/ or croak 'You can either have a ns requirement, or a ":" in your path segment';
Branch: 1 branch
BranchTrueFalseTotal
$attr_name =~ /\:/ and croak("You can either have a ns requirement, or a \":\" in your path segment") 0 2 2
151 2 my $actual_attr_value = $self->{ns_data}{"$attr_ns:$attr_name"};
152 2 ▶ defined $actual_attr_value or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $actual_attr_value or return 0 1 1 2
153 1 ▶ ! defined $attr_value or $attr_value eq $actual_attr_value or return 0;
Branch: 1 branch
BranchTrueFalseTotal
not defined $attr_value or $attr_value eq $actual_attr_value or return 0 1 0 1
Condition33%1/3
not defined $attr_value or $attr_value eq $actual_attr_value
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $attr_value or $attr_value eq $actual_attr_value
not defined $attr_value $attr_value eq $actual_attr_value
Truth table33%1/3
not(A) or B
A= not defined $attr_valueB= $attr_value eq $actual_attr_value
ABresult
1X1
011
000
154 } else {
155 # my $actual_attr_value = $self->attr($attr_name);
156 # defined $actual_attr_value or return 0;
157 # ! exists $self->{ns_data}{}
158 0 croak 'empty ns in path segment';
159 }
160 }
161  
162 82 return 1;
163 }
164  
165 197 ▶sub children {
Subroutine children: called CC=3 SCAR=11.0
Pod undocumented
166 197 my $self = shift;
167 197 my $path_segment = shift;
168  
169 197 ▶ $path_segment = '' if ! defined $path_segment;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path_segment 132 65 197
170  
171 197 my @all_children = grep { defined $_->{el_name} } @{$self->{content}};
172 197 ▶ length $path_segment or return @all_children;
Branch: 1 branch
BranchTrueFalseTotal
length $path_segment or return @all_children 65 132 197
173  
174 65 my ($el_name, $el_ns, $attrs) = _parse_description($path_segment);
175 65 my $desc = { el_name => $el_name, el_ns => $el_ns, attrs => $attrs };
176  
177 65 return grep $_->cmp_element($desc), @all_children;
178 }
179  
180 41 ▶sub path {
Subroutine path: called CC=7 SCAR=19.5
Pod undocumented
181 41 my $self = shift;
182 41 my $path = shift;
183  
184 41 my $original_path = $path;
185 41 my $path_starts_with_root = $path =~ m|^/|;
186 41 ▶ $path = "/$path" unless $path_starts_with_root;
Branch: 1 branch
BranchTrueFalseTotal
unless $path_starts_with_root 29 12 41
187 41 my @path_segments = $path =~ m!
188 # slash
189 \/
190  
191 (
192 # allowed strings
193 (?:
194 # escaped "/"
195 \\ \/
196 |
197 # escaped "["
198 \\ \[
199 |
200 # escaped "{"
201 \\ \{
202 |
203 # non- "/", "[", "]"
204 [^\/\[\{]
205 |
206 # attribute
207 \[
208 (?: \\ \] | [^\]] )*
209 \]
210 |
211 # namespace
212 \{
213 (?: \\ \} | [^\}] )*
214 \}
215 )*
216 )
217 !gx;
218  
219 41 my @result = ($self);
220 41 ▶ $self->cmp_element(shift @path_segments) or return if $path_starts_with_root;
Branch: 1 branch
BranchTrueFalseTotal
if $path_starts_with_root 12 29 41
Condition80%4/5
$path_starts_with_root && ($self->cmp_element(shift @path_segments) || (return))
!ll&&!rl&&r
29120
$self->cmp_element(shift @path_segments) or return
l!l
111
MC/DC0%0/2
$path_starts_with_root && ($self->cmp_element(shift @path_segments) || (return))
$path_starts_with_root $self->cmp_element(shift @path_segments)
Truth table66%2/3
A && B
A= $path_starts_with_rootB= $self->cmp_element(shift @path_segments)
ABresult
0X0
100
111
221 40 foreach my $path_segment (@path_segments) {
222 58 ▶ @result = map $_->children($path_segment), @result or return;
Branch: 1 branch
BranchTrueFalseTotal
@result = map($_->children($path_segment), @result) or return 58 0 58
223 }
224 40 ▶ return wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 31 40
225 }
226  
227 53 ▶sub text {
Subroutine text: called CC=11 SCAR=24.0
Pod undocumented
228 53 my $self = shift;
229 53 ▶ my $flags = (@_ and ref $_[-1]) ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] ? : 29 24 53
Condition100%3/3
@_ and ref $_[-1]
!ll&&!rl&&r
21329
MC/DC100%2/2
@_ and ref $_[-1]
@_ ref $_[-1]
Truth table100%3/3
A and B
A= @_B= ref $_[-1]
ABresult
0X0
100
111
230 53 ▶ my $set_value = @_ ? (defined $_[0] ? shift : '') : undef;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 50 53
defined $_[0] ? : 2 1 3
231  
232 53 ▶ if (! defined $set_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set_value) { } 50 3 53
233 50 my $value = '';
234 50 ▶ if ($self->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"}) 28 22 50
235 28 $value .= $_->text($flags) foreach @{ $self->{content} };
236 }
237 50 ▶ if ($self->{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"text"}) 22 28 50
238 22 my $temp_value = $self->{text};
239 22 ▶ $temp_value = trim $temp_value if $flags->{strip};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"strip"} 2 20 22
240 22 $value .= $temp_value;
241 }
242 50 return $value;
243 } else {
244 3 ▶ if (length $set_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $set_value) { } 1 2 3
245 1 my $entry = bless {
246 text => $set_value,
247 parent => $self
248 }, 'XML::MyXML::Object';
249 1 weaken $entry->{parent};
250 1 $self->{content} = [ $entry ];
251 } else {
252 2 $self->{content} = [];
253 }
254 }
255 }
256  
257 5 *value = \&text;
258  
259 7 ▶sub inner_xml {
Subroutine inner_xml: called CC=9 SCAR=22.0
Pod undocumented
260 7 my $self = shift;
261 7 ▶ my $flags = (@_ and ref $_[-1]) ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] ? : 2 5 7
Condition100%3/3
@_ and ref $_[-1]
!ll&&!rl&&r
232
MC/DC100%2/2
@_ and ref $_[-1]
@_ ref $_[-1]
Truth table100%3/3
A and B
A= @_B= ref $_[-1]
ABresult
0X0
100
111
262 7 ▶ my $set_xml = @_ ? defined $_[0] ? shift : '' : undef;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 3 7
defined $_[0] ? : 3 1 4
263  
264 7 ▶ if (! defined $set_xml) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set_xml) { } 3 4 7
265 3 my $xml = $self->to_xml($flags);
266 3 $xml =~ s/^\<.*?\>//s;
267 3 $xml =~ s/\<\/[^\>]*\>\z//s; # nothing to remove if empty element
268 3 return $xml;
269 } else {
270 4 my $xml = "<div>$set_xml</div>";
271 4 my $obj = XML::MyXML::xml_to_object($xml, $flags);
272 4 $self->{content} = [];
273 4 ▶ foreach my $child (@{ $obj->{content} || [] }) {
Condition100%2/2
$obj->{'content'} || []
l!l
31
MC/DC100%1/1
$obj->{'content'} || []
$obj->{'content'}
Truth table100%2/2
A
A= $obj->{'content'}
Aresult
11
00
274 5 $child->{parent} = $self;
275 5 weaken $child->{parent};
276 5 push @{ $self->{content} }, $child;
277 5 ▶ $child->_apply_namespace_declarations if $child->{el_name};
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"el_name"} 4 1 5
278 }
279 }
280 }
281  
282 199 ▶sub attr {
Subroutine attr: called CC=7 SCAR=19.5
Pod undocumented
283 199 my $self = shift;
284 199 my $attr_name = shift;
285 199 ▶ my $flags = ref $_[-1] ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] ? : 0 199 199
286 199 my ($set_to, $must_set);
287 199 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 195 199
288 4 $set_to = shift;
289 4 $must_set = 1;
290 }
291  
292 199 ▶ if (defined $attr_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr_name) { } 67 132 199
293 67 ▶ if ($must_set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($must_set) { } 4 63 67
294 4 ▶ if (defined ($set_to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set_to) { } 3 1 4
295 3 $self->{attrs}{$attr_name} = $set_to;
296 } else {
297 1 delete $self->{attrs}{$attr_name};
298 }
299 4 ▶ if ($attr_name =~ /^xmlns(\:|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_name =~ /^xmlns(\:|\z)/) 2 2 4
300 2 $self->_apply_namespace_declarations;
301 }
302 4 return $set_to;
303 } else {
304 63 return $self->{attrs}->{$attr_name};
305 }
306 } else {
307 132 return %{$self->{attrs}};
308 }
309 }
310  
311 5 ▶sub tag {
Subroutine tag: called CC=4 SCAR=14.0
Pod undocumented
312 5 my $self = shift;
313 5 ▶ my $flags = shift || {};
Condition100%2/2
shift() || {}
l!l
23
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
314  
315 5 my $el_name = $self->{el_name};
316 5 ▶ if (defined $el_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $el_name) { } 5 0 5
317 5 ▶ $el_name =~ s/^.*\:// if $flags->{strip_ns};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"strip_ns"} 1 4 5
318 5 return $el_name;
319 } else {
320 0 return undef;
321 }
322 }
323  
324 5 *name = \&tag;
325  
326 2 ▶sub parent {
Subroutine parent: called CC=1 SCAR=0.0
Pod undocumented
327 2 my $self = shift;
328  
329 2 return $self->{parent};
330 }
331  
332 13 ▶sub simplify {
Subroutine simplify: called CC=5 SCAR=16.6
Pod undocumented
333 13 my $self = shift;
334 13 ▶ my $flags = shift || {};
Condition100%2/2
shift() || {}
l!l
112
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
335  
336 13 my $simple = XML::MyXML::_objectarray_to_simple([$self], $flags);
337  
338 13 ▶ if ($flags->{internal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{"internal"}) 5 8 13
339 5 ▶ $simple =
Branch: 2 branches
BranchTrueFalseTotal
ref $simple eq 'HASH' ? : 5 0 5
ref $simple eq 'ARRAY' ? : 0 0 0
340 ref $simple eq 'HASH' ? (values %$simple)[0]
341 : ref $simple eq 'ARRAY' ? $simple->[1]
342 : croak;
343 }
344  
345 13 return $simple;
346 }
347  
348 21 ▶sub to_xml {
Subroutine to_xml: called CC=7 SCAR=21.3
Pod undocumented
349 21 my $self = shift;
350 21 ▶ my $flags = shift || {};
Condition100%2/2
shift() || {}
l!l
1011
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
351  
352 21 my $decl = '';
353 21 ▶ $decl .= qq'<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n' if $flags->{complete};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"complete"} 0 21 21
354 21 my $xml = XML::MyXML::_objectarray_to_xml([$self]);
355 $xml = XML::MyXML::tidy_xml($xml, {
356 %$flags,
357 bytes => 0,
358 complete => 0,
359 save => undef
360 21 ▶ }) if $flags->{tidy};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"tidy"} 3 18 21
361 21 $xml = $decl . $xml;
362 21 ▶ if (defined $flags->{save}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flags->{"save"}) 0 21 21
363 0 ▶ open my $fh, '>', $flags->{save} or croak "Error: Couldn't open file '$flags->{save}' for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $flags->{"save"} or croak(qq[Error: Couldn't open file '$flags->{"save"}' for writing: $!]) 0 0 0
364 0 binmode $fh, ':encoding(UTF-8)';
365 0 print $fh $xml;
366 0 close $fh;
367 }
368 21 ▶ $xml = encode_utf8 $xml if $flags->{bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"bytes"} 4 17 21
369 21 return $xml;
370 }
371  
372 1 ▶sub to_tidy_xml {
Subroutine to_tidy_xml: called CC=2 SCAR=7.1
Pod undocumented
373 1 my $self = shift;
374 1 ▶ my $flags = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
375  
376 1 return $self->to_xml({ %$flags, tidy => 1 });
377 }
378  
379 132 ▶sub _apply_namespace_declarations {
Subroutine _apply_namespace_declarations: called CC=17 SCAR=28.5
380 132 my $self = shift;
381  
382 # only elements
383 132 ▶ $self->{el_name} or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"el_name"} or return 132 0 132
384  
385 132 my %attr = $self->attr;
386  
387 # parse namespace declarations
388 132 my ($ns_info, @cancel_declarations) = ({});
389 132 foreach my $ns_decl_attr_name (grep /^xmlns(\:|\z)/, keys %attr) {
390 7 my ($ns_prefix) = $ns_decl_attr_name =~ /^xmlns(?:\:(.+))?\z/;
391 7 ▶ $ns_prefix = '' if ! defined $ns_prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ns_prefix 5 2 7
392 7 ▶ if (length $attr{$ns_decl_attr_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $attr{$ns_decl_attr_name}) { } 5 2 7
393 5 $ns_info->{$ns_prefix} = $attr{$ns_decl_attr_name};
394 } else {
395 2 push @cancel_declarations, $ns_prefix;
396 }
397 }
398  
399 # insert these declarations into the full_ns_info hashref
400 $self->{full_ns_info} = (%$ns_info or @cancel_declarations) ? {
401 6 %{ $self->{parent}{full_ns_info} },
402 %$ns_info,
403 132 ▶ } : $self->{parent}{full_ns_info};
Branch: 1 branch
BranchTrueFalseTotal
%$ns_info || @cancel_declarations ? : 6 126 132
Condition100%3/3
%$ns_info or @cancel_declarations
l!l&&r!l&&!r
42126
MC/DC100%2/2
%$ns_info or @cancel_declarations
%$ns_info @cancel_declarations
Truth table100%3/3
A or B
A= %$ns_infoB= @cancel_declarations
ABresult
1X1
011
000
404  
405 # remove cancelled declarations (can cancel with ns name = "")
406 132 delete @{ $self->{full_ns_info} }{@cancel_declarations};
407  
408 # ns_data is...
409 # $ns_name: => undef for element name
410 # $ns_name:$attr_localpart => $attr_value for attributes
411 132 $self->{ns_data} = {};
412  
413 # apply all active declarations to element
414 132 my $el_name = $self->{el_name};
415 132 my $num_colons = () = $el_name =~ /(\:)/g;
416 132 my $ns_name = do {
417 132 ▶ if ($num_colons == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($num_colons == 0) { } 128 4 132
elsif ($num_colons == 1) { } 4 0 4
418 128 $self->{full_ns_info}{''};
419 } elsif ($num_colons == 1) {
420 4 my ($prefix) = $el_name =~ /^(.+)?\:./; # colon must not be at start or end
421 4 ▶ defined $prefix ? $self->{full_ns_info}{$prefix} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 4 0 4
422 } else {
423 0 undef;
424 }
425 };
426 132 ▶ $self->{ns_data}{"$ns_name:"} = undef if defined $ns_name and length $ns_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ns_name and length $ns_name 7 125 132
Condition66%2/3
defined $ns_name and length $ns_name
!ll&&!rl&&r
12507
MC/DC50%1/2
defined $ns_name and length $ns_name
defined $ns_name length $ns_name
Truth table66%2/3
A and B
A= defined $ns_nameB= length $ns_name
ABresult
0X0
100
111
427  
428 # apply all active declarations to attributes
429 132 foreach my $attr_name (keys %attr) {
430 58 ▶ if ($attr_name =~ /^([^\:]+)\:([^\:]+)\z/) { # if has one colon, not at the edges
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_name =~ /^([^\:]+)\:([^\:]+)\z/) 7 51 58
431 7 my ($prefix, $localpart) = ($1, $2);
432 7 my $ns_name = $self->{full_ns_info}{$prefix};
433 7 ▶ $self->{ns_data}{"$ns_name:$localpart"} = $attr{$attr_name}
Branch: 1 branch
BranchTrueFalseTotal
if defined $ns_name and length $ns_name 4 3 7
Condition66%2/3
defined $ns_name and length $ns_name
!ll&&!rl&&r
304
MC/DC50%1/2
defined $ns_name and length $ns_name
defined $ns_name length $ns_name
Truth table66%2/3
A and B
A= defined $ns_nameB= length $ns_name
ABresult
0X0
100
111
434 if defined $ns_name and length $ns_name;
435 }
436 }
437  
438 # continue by applying to all children (and further ancestors)
439 132 $_->_apply_namespace_declarations foreach $self->children;
440 }
441  
442 5 1;
« MyXML.pm ↑ Summary MyXML/Util.pm »