blib/lib/XML/Struct/Reader.pm

filter: Statementstmt 91.1% 145 / 159 Branchbran 81.9% 95 / 116 Conditioncond 76.9% 50 / 65 MC/DCmcdc 57.5% 23 / 40 Subroutinesub 93.3% 28 / 30 Podpod 83.3% 5 / 6 totaltotal 83.1% 346 / 416 SCAR 46.2
CC
81
Cov
85%
_trigger_from
37.8
BUILD
15.1
readContent
9.1
CRAP 101.9
↑ Summary blib/lib/XML/Struct/Writer.pm »
1 package XML::Struct::Reader;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 our @CARP_NOT = qw(XML::Struct);
7 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use XML::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION = '0.25';
11  
12 41 ▶has whitespace => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
13 31 ▶has attributes => (is => 'ro', default => sub { 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
14 31 ▶has path => (is => 'ro', default => sub { '*' }, isa => \&_checkPath);
Subroutine __ANON__: called CC=1 SCAR=0.0
15 has stream => (is => 'rw',
16 lazy => 1,
17 builder => sub {
18 0 ▶ XML::LibXML::Reader->new( { IO => \*STDIN } )
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine _build_stream: not called CC=1 SCAR=6.9
19 },
20 isa => sub {
21 40 ▶ die 'stream must be an XML::LibXML::Reader'
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Reader") 0 40 40
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Reader")
!ll&&!rl&&r
0040
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("XML::LibXML::Reader")
builtin::blessed($_[0]) $_[0]->isa("XML::LibXML::Reader")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("XML::LibXML::Reader")
ABresult
0X0
100
111
22 unless blessed $_[0] && $_[0]->isa('XML::LibXML::Reader');
23 }
24 5 );
25 5 has from => (is => 'ro', trigger => 1);
26 37 ▶has ns => (is => 'ro', default => sub { 'keep' }, trigger => 1);
Subroutine __ANON__: called CC=1 SCAR=0.0
27 has depth => (is => 'ro', coerce => sub {
28 11 ▶ (defined $_[0] and $_[0] =~ /^\+?\d+/) ? $_[0] : undef
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /^\+?\d+/ ? : 9 2 11
Condition100%3/3
defined $_[0] and $_[0] =~ /^\+?\d+/
!ll&&!rl&&r
119
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^\+?\d+/
defined $_[0] $_[0] =~ /^\+?\d+/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^\+?\d+/
ABresult
0X0
100
111
29 5 });
30 37 ▶has deep => (is => 'ro', default => sub { '' } );
Subroutine __ANON__: called CC=1 SCAR=0.0
31 25 ▶has simple => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
32 33 ▶has root => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
33 41 ▶has content => (is => 'ro', default => sub { 'content' });
Subroutine __ANON__: called CC=1 SCAR=0.0
34  
35 5 use XML::LibXML::Reader qw(
36 XML_READER_TYPE_ELEMENT
37 XML_READER_TYPE_TEXT
38 XML_READER_TYPE_CDATA
39 XML_READER_TYPE_SIGNIFICANT_WHITESPACE
40 XML_READER_TYPE_END_ELEMENT
41 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 sub BUILD {
44 42 ▶ my ($self) = @_;
Subroutine BUILD: called CC=13 SCAR=27.1
Pod undocumented
45
46 # make sure that option 'deep' and 'depth' are only set if it makes sense
47
48 42 ▶ if ($self->deep eq 'simple') {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->deep eq 'simple') { } 3 39 42
elsif ($self->deep eq 'struct') { } 0 39 39
elsif ($self->deep eq '') { } 37 2 39
elsif (not $self->deep =~ /^(dom|raw)$/) { } 0 2 2
49 3 ▶ if ($self->simple or (defined $self->depth and $self->depth == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->simple or defined $self->depth and $self->depth == 0) 3 0 3
Condition50%3/6
$self->simple or defined $self->depth and $self->depth == 0
l!l&&r!l&&!r
120
defined $self->depth and $self->depth == 0
!ll&&!rl&&r
002
MC/DC0%0/3
$self->simple or defined $self->depth and $self->depth == 0
$self->simple defined $self->depth $self->depth == 0
Truth table50%2/4
A or B and C
A= $self->simpleB= defined $self->depthC= $self->depth == 0
ABCresult
1XX1
0111
00X0
0100
50 # (deep = simple, simple = 1) or (deep = simple, depth = 0)
51 3 $self->{simple} = 1;
52 3 delete $self->{depth};
53 3 $self->{deep} = '';
54 }
55 } elsif ($self->deep eq 'struct') {
56 0 $self->{deep} = '';
57 } elsif ($self->deep eq '') {
58 37 ▶ $self->{deep} = $self->simple ? '' : 'simple';
Branch: 1 branch
BranchTrueFalseTotal
$self->simple ? : 16 21 37
59 } elsif ($self->deep !~ /^(dom|raw)$/) {
60 0 croak "option deep must be simple, struct, dom, or raw!";
61 }
62  
63 42 ▶ if (($self->depth || 0) and $self->root and $self->simple) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->depth || 0 and $self->root and $self->simple) 2 40 42
Condition87%7/8
$self->depth || 0 and $self->root and $self->simple
!ll&&!rl&&r
4002
$self->depth || 0 and $self->root
!ll&&!rl&&r
3822
$self->depth or 0
l!l
438
MC/DC66%2/3
$self->depth || 0 and $self->root and $self->simple
$self->depth $self->root $self->simple
Truth table75%3/4
A and B and C
A= $self->depthB= $self->rootC= $self->simple
ABCresult
0XX0
10X0
1100
1111
64 2 $self->{depth} = $self->{depth}-1;
65 }
66 }
67  
68 sub _trigger_from {
69 40 ▶ my ($self, $from) = @_;
Subroutine _trigger_from: called CC=22 SCAR=36.3
70  
71 40 ▶ unless (blessed $from and $from->isa('XML::LibXML::Reader')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($from) and $from->isa("XML::LibXML::Reader")) 31 9 40
Condition100%3/3
builtin::blessed($from) and $from->isa("XML::LibXML::Reader")
!ll&&!rl&&r
2929
MC/DC100%2/2
builtin::blessed($from) and $from->isa("XML::LibXML::Reader")
builtin::blessed($from) $from->isa("XML::LibXML::Reader")
Truth table100%3/3
A and B
A= builtin::blessed($from)B= $from->isa("XML::LibXML::Reader")
ABresult
0X0
100
111
72 31 my %options;
73  
74 31 ▶ if (ref $from and ref $from eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $from and ref $from eq "HASH") 0 31 31
Condition66%2/3
ref $from and ref $from eq "HASH"
!ll&&!rl&&r
2830
MC/DC0%0/2
ref $from and ref $from eq "HASH"
ref $from ref $from eq "HASH"
Truth table66%2/3
A and B
A= ref $fromB= ref $from eq "HASH"
ABresult
0X0
100
111
75 0 %options = %$from;
76 0 ▶ $from = delete $options{from} if exists $options{from};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"from"} 0 0 0
77 }
78  
79 31 ▶ if (!defined $from or $from eq '-') {
Branch: 9 branches
BranchTrueFalseTotal
if (not defined $from or $from eq '-') { } 0 31 31
elsif (not ref $from and $from =~ /^</) { } 9 22 31
elsif (ref $from and ref $from eq 'SCALAR') { } 1 21 22
elsif (ref $from and ref $from eq 'GLOB') { } 0 21 21
elsif (builtin::blessed($from) and $from->isa('XML::LibXML::Document')) { } 1 20 21
elsif (builtin::blessed($from) and $from->isa('XML::LibXML::Element')) { } 1 19 20
elsif (builtin::blessed($from)) { } 0 19 19
elsif (not ref $from) { } 19 0 19
elsif (not grep({$_ =~ /^(IO|string|location|FD|DOM)$/;} keys %options)) { } 0 0 0
Condition33%1/3
not defined $from or $from eq "-"
l!l&&r!l&&!r
0031
MC/DC0%0/2
not defined $from or $from eq "-"
not defined $from $from eq "-"
Truth table33%1/3
not(A) or B
A= not defined $fromB= $from eq "-"
ABresult
1X1
011
000
80 0 $options{IO} = \*STDIN
81 ▶ } elsif( !ref $from and $from =~ /^</ ) {
Condition100%3/3
not ref $from and $from =~ /^</
!ll&&!rl&&r
3199
MC/DC100%2/2
not ref $from and $from =~ /^</
not ref $from $from =~ /^</
Truth table100%3/3
not(A) and B
A= not ref $fromB= $from =~ /^</
ABresult
0X0
100
111
82 9 $options{string} = $from;
83 ▶ } elsif( ref $from and ref $from eq 'SCALAR' ) {
Condition100%3/3
ref $from and ref $from eq "SCALAR"
!ll&&!rl&&r
1921
MC/DC100%2/2
ref $from and ref $from eq "SCALAR"
ref $from ref $from eq "SCALAR"
Truth table100%3/3
A and B
A= ref $fromB= ref $from eq "SCALAR"
ABresult
0X0
100
111
84 1 $options{string} = $$from;
85 ▶ } elsif( ref $from and ref $from eq 'GLOB' ) {
Condition66%2/3
ref $from and ref $from eq "GLOB"
!ll&&!rl&&r
1920
MC/DC0%0/2
ref $from and ref $from eq "GLOB"
ref $from ref $from eq "GLOB"
Truth table66%2/3
A and B
A= ref $fromB= ref $from eq "GLOB"
ABresult
0X0
100
111
86 0 $options{FD} = $from;
87 ▶ } elsif( blessed $from and $from->isa('XML::LibXML::Document') ) {
Condition100%3/3
builtin::blessed($from) and $from->isa("XML::LibXML::Document")
!ll&&!rl&&r
1911
MC/DC100%2/2
builtin::blessed($from) and $from->isa("XML::LibXML::Document")
builtin::blessed($from) $from->isa("XML::LibXML::Document")
Truth table100%3/3
A and B
A= builtin::blessed($from)B= $from->isa("XML::LibXML::Document")
ABresult
0X0
100
111
88 1 $options{DOM} = $from;
89 ▶ } elsif( blessed $from and $from->isa('XML::LibXML::Element') ) {
Condition66%2/3
builtin::blessed($from) and $from->isa("XML::LibXML::Element")
!ll&&!rl&&r
1901
MC/DC50%1/2
builtin::blessed($from) and $from->isa("XML::LibXML::Element")
builtin::blessed($from) $from->isa("XML::LibXML::Element")
Truth table66%2/3
A and B
A= builtin::blessed($from)B= $from->isa("XML::LibXML::Element")
ABresult
0X0
100
111
90 1 my $doc = XML::LibXML->createDocument;
91 1 $doc->setDocumentElement($from);
92 1 $options{DOM} = $doc;
93 } elsif( blessed $from ) {
94 0 $options{IO} = $from;
95 } elsif( !ref $from ) {
96 19 $options{location} = $from; # filename or URL
97 0 } elsif( ! grep { $_ =~ /^(IO|string|location|FD|DOM)$/} keys %options ) {
98 0 croak "invalid option 'from': $from";
99 }
100
101 $from = XML::LibXML::Reader->new( %options )
102 or die "failed to create XML::LibXML::Reader with "
103 31 ▶ . join(', ',map { "$_=".$options{$_} } keys %options )."\n";
Branch: 1 branch
BranchTrueFalseTotal
$from = "XML::LibXML::Reader"->new(%options) or die 'failed to create XML::LibXML::Reader with ' . join(", ", map({"$_=" . $options{$_};} keys %options)) . "\n" 0 31 31
104 }
105  
106 40 $self->stream($from);
107 }
108  
109  
110 sub _trigger_ns {
111 5 ▶ my ($self, $ns) = @_;
Subroutine _trigger_ns: called CC=4 SCAR=18.9
112  
113 5 ▶ if (!defined $ns or $ns eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $ns or $ns eq '') { } 0 5 5
elsif (not $ns =~ /^(keep|strip|disallow)?$/) { } 0 5 5
Condition33%1/3
not defined $ns or $ns eq ""
l!l&&r!l&&!r
005
MC/DC0%0/2
not defined $ns or $ns eq ""
not defined $ns $ns eq ""
Truth table33%1/3
not(A) or B
A= not defined $nsB= $ns eq ""
ABresult
1X1
011
000
114 0 $self->{ns} = 'keep';
115 } elsif ($ns !~ /^(keep|strip|disallow)?$/) {
116 0 croak "invalid option 'ns': $ns";
117 }
118 }
119  
120  
121 sub _checkPath {
122 48 ▶ my $path = shift;
Subroutine _checkPath: called CC=3 SCAR=11.4
123  
124 48 ▶ die "invalid path: $path" if $path =~ qr{\.\.|.//|^\.};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ qr"\.\.|.//|^\." 0 48 48
125 48 ▶ die "relative path not supported: $path" if $path =~ qr{^[^/]+/};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ qr"^[^/]+/" 0 48 48
126  
127 48 return $path;
128 }
129  
130 sub _nameMatch {
131 77 ▶ return ($_[0] eq '*' or $_[0] eq $_[1]);
Subroutine _nameMatch: called CC=2 SCAR=6.9
Condition100%3/3
$_[0] eq '*' || $_[0] eq $_[1]
l!l&&r!l&&!r
381722
MC/DC100%2/2
$_[0] eq '*' || $_[0] eq $_[1]
$_[0] eq '*' $_[0] eq $_[1]
Truth table100%3/3
A || B
A= $_[0] eq '*'B= $_[0] eq $_[1]
ABresult
1X1
011
000
132 }
133  
134 # read to the next element
135 # TODO: use XML::LibXML->nextPatternMatch
136 sub _nextPatternMatch {
137 62 ▶ my ($self, $stream, $path) = @_;
Subroutine _nextPatternMatch: called CC=8 SCAR=20.8
138  
139 62 $path =~ s{^//}{};
140 62 ▶ $path .= '*' if $path =~ qr{^$|/$};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ qr"^$|/$" 2 60 62
141  
142 62 my @parts = split '/', $path;
143 62 my $relative = $parts[0] ne '';
144  
145 62 while(1) {
146 151 ▶ return if !$stream->read; # end or error
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->read 16 135 151
147 135 ▶ next if $stream->nodeType != XML_READER_TYPE_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $stream->nodeType != 1 58 77 135
148  
149 # printf " %d=%d %s:%s==%s\n", $stream->depth, scalar @parts, $stream->nodePath, $stream->name, join('/', @parts);
150  
151 77 my $name = $self->_name($stream);
152  
153 77 ▶ if ($relative) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative) { } 49 28 77
154 49 ▶ if (_nameMatch($parts[0], $name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_nameMatch($parts[0], $name)) 33 16 49
155 33 last;
156 }
157 } else {
158 28 ▶ if (!_nameMatch($parts[$stream->depth+1], $name)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not _nameMatch($parts[$stream->depth + 1], $name)) { } 6 22 28
elsif ($stream->depth == scalar @parts - 2) { } 13 9 22
159 6 $stream->nextSibling();
160 } elsif ($stream->depth == scalar @parts - 2) {
161 13 last;
162 }
163 }
164 }
165  
166 46 return 1;
167 }
168  
169 sub readNext {
170 62 ▶ my $self = shift;
Subroutine readNext: called CC=5 SCAR=16.1
Pod documented
171 62 ▶ my $stream = blessed $_[0] ? shift() : $self->stream;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 2 60 62
172 62 ▶ my $path = defined $_[0] ? _checkPath($_[0]) : $self->path;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 6 56 62
173  
174 62 ▶ return unless $self->_nextPatternMatch($stream, $path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nextPatternMatch($stream, $path) 16 46 62
175  
176 46 my $xml = $self->readElement($stream);
177  
178 44 ▶ return $self->simple ? XML::Struct::Simple->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->simple ? : 23 21 44
179 root => $self->root,
180 attributes => $self->attributes,
181 depth => $self->depth,
182 content => $self->content,
183 )->transform($xml) : $xml;
184 }
185  
186 5 *read = \&readNext;
187  
188  
189 sub readDocument {
190 30 ▶ my $self = shift;
Subroutine readDocument: called CC=3 SCAR=11.0
Pod documented
191 30 my @document;
192
193 30 ▶ while(my $element = $self->read(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $element = $self->read(@_)) 30 12 42
194 30 ▶ return $element unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 16 14 30
195 14 push @document, $element;
196 }
197  
198 12 return @document;
199 }
200  
201 sub _name {
202 287 ▶ my ($self, $stream) = @_;
Subroutine _name: called CC=4 SCAR=13.9
203  
204 287 ▶ if ($self->ns eq 'strip') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ns eq 'strip') { } 10 277 287
elsif ($self->ns eq 'disallow') { } 15 262 277
205 10 return $stream->localName;
206 } elsif( $self->ns eq 'disallow' ) {
207 15 ▶ if ( $stream->name =~ /^xmlns(:.*)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->name =~ /^xmlns(:.*)?$/) 2 13 15
208 2 croak "namespaces not allowed at line ".$stream->lineNumber;
209 }
210 }
211  
212 275 return $stream->name;
213 }
214  
215  
216 sub readElement {
217 182 ▶ my $self = shift;
Subroutine readElement: called CC=9 SCAR=22.0
Pod documented
218 182 ▶ my $stream = @_ ? shift : $self->stream;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 182 0 182
219  
220 182 my @element = ($self->_name($stream));
221  
222 # TODO: dom or raw
223 182 ▶ if (defined $self->depth and $stream->depth >= $self->depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->depth and $stream->depth >= $self->depth) 28 154 182
Condition100%3/3
defined $self->depth and $stream->depth >= $self->depth
!ll&&!rl&&r
148628
MC/DC100%2/2
defined $self->depth and $stream->depth >= $self->depth
defined $self->depth $stream->depth >= $self->depth
Truth table100%3/3
A and B
A= defined $self->depthB= $stream->depth >= $self->depth
ABresult
0X0
100
111
224 28 ▶ if ($self->deep eq 'dom') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->deep eq 'dom') { } 1 27 28
elsif ($self->deep eq 'raw') { } 1 26 27
225 1 my $dom = $stream->copyCurrentNode(1);
226 1 $stream->next;
227 1 return $dom;
228 } elsif ($self->deep eq 'raw') {
229 1 my $xml = $stream->readOuterXml();
230 1 $stream->next;
231 1 return $xml;
232 }
233 #copyCurrentNode
234 #if (defined $self->depth and $self->depth == $stream->depth ) {
235 #print $stream->depth." ".$self->deep."!".$element[0]."\n";
236 #}
237 }
238  
239 180 ▶ if ($self->attributes) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->attributes) { } 130 50 180
elsif (not $stream->isEmptyElement) { } 38 12 50
240 130 my $attr = $self->readAttributes($stream);
241 128 ▶ my $children = $stream->isEmptyElement ? [ ] : $self->readContent($stream);
Branch: 1 branch
BranchTrueFalseTotal
$stream->isEmptyElement ? : 31 97 128
242 128 push @element, $attr, $children;
243 } elsif( !$stream->isEmptyElement ) {
244 38 push @element, $self->readContent($stream);
245 }
246  
247 178 return \@element;
248 }
249  
250  
251 sub readAttributes {
252 130 ▶ my $self = shift;
Subroutine readAttributes: called CC=6 SCAR=17.9
Pod documented
253 130 ▶ my $stream = @_ ? shift : $self->stream;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 130 0 130
254  
255 130 ▶ return { } if $stream->moveToFirstAttribute != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $stream->moveToFirstAttribute != 1 104 26 130
256  
257 26 my $attr = { };
258 26 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$stream->moveToNextAttribute and do { do { if ($self->ns ne "strip" or not $stream->name =~ /^xmlns(:.*)?$/) { $$attr{$self->_name($stream)} = $stream->value; } } } 4 24 28
259 30 ▶ if ($self->ns ne 'strip' or $stream->name !~ /^xmlns(:.*)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ns ne "strip" or not $stream->name =~ /^xmlns(:.*)?$/) 28 2 30
Condition100%3/3
$self->ns ne "strip" or not $stream->name =~ /^xmlns(:.*)?$/
l!l&&r!l&&!r
2532
MC/DC100%2/2
$self->ns ne "strip" or not $stream->name =~ /^xmlns(:.*)?$/
$self->ns ne "strip" not $stream->name =~ /^xmlns(:.*)?$/
Truth table100%3/3
A or not(B)
A= $self->ns ne "strip"B= not $stream->name =~ /^xmlns(:.*)?$/
ABresult
1X1
011
000
260 28 $attr->{ $self->_name($stream) } = $stream->value;
261 }
262 } while ($stream->moveToNextAttribute);
263 24 $stream->moveToElement;
264  
265 24 return $attr;
266 }
267  
268  
269 sub readContent {
270 135 ▶ my $self = shift;
Subroutine readContent: called CC=9 SCAR=22.1
Pod documented
271 135 ▶ my $stream = @_ ? shift : $self->stream;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 135 0 135
272  
273 135 my @children;
274 135 while(1) {
275 503 $stream->read;
276 503 my $type = $stream->nodeType;
277  
278 503 ▶ last if !$type or $type == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if not $type or $type == 15 135 368 503
Condition66%2/3
not $type or $type == 15
l!l&&r!l&&!r
0135368
MC/DC50%1/2
not $type or $type == 15
not $type $type == 15
Truth table66%2/3
not(A) or B
A= not $typeB= $type == 15
ABresult
1X1
011
000
279  
280 368 ▶ if ($type == XML_READER_TYPE_ELEMENT) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 1) { } 136 232 368
elsif ($type == 3 or $type == 4) { } 60 172 232
elsif ($type == 14 and $self->whitespace) { } 1 171 172
281 136 push @children, $self->readElement($stream);
282 ▶ } elsif ($type == XML_READER_TYPE_TEXT or $type == XML_READER_TYPE_CDATA ) {
Condition100%3/3
$type == 3 or $type == 4
l!l&&r!l&&!r
582172
MC/DC100%2/2
$type == 3 or $type == 4
$type == 3 $type == 4
Truth table100%3/3
A or B
A= $type == 3B= $type == 4
ABresult
1X1
011
000
283 60 push @children, $stream->value;
284 ▶ } elsif ($type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE && $self->whitespace) {
Condition66%2/3
$type == 14 and $self->whitespace
!ll&&!rl&&r
01711
MC/DC50%1/2
$type == 14 and $self->whitespace
$type == 14 $self->whitespace
Truth table66%2/3
A and B
A= $type == 14B= $self->whitespace
ABresult
0X0
100
111
285 1 push @children, $stream->value;
286 }
287 }
288
289 135 return \@children;
290 }
291  
292 5 1;
293 __END__
↑ Summary blib/lib/XML/Struct/Writer.pm »