MyXML/Object.pm

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