blib/lib/XML/Stream/Parser.pm

filter: Statementstmt 74.6% 212 / 284 Branchbran 61.9% 78 / 126 Conditioncond 63.3% 19 / 30 MC/DCmcdc 38.8% 7 / 18 Subroutinesub 90.6% 29 / 32 Podpod 0.0% 0 / 15 totaltotal 68.3% 345 / 505 CC 75 SCAR 28.5
CC
75
Cov
70%
characters
42.0
parse
33.6
endElement
30.0
CRAP 17.3
« blib/lib/XML/Stream/Tools.pm ↑ Summary blib/lib/XML/Stream/XPath/Op.pm »
1 ##############################################################################
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Library General Public
5 # License as published by the Free Software Foundation; either
6 # version 2 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Library General Public License for more details.
12 #
13 # You should have received a copy of the GNU Library General Public
14 # License along with this library; if not, write to the
15 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 # Boston, MA 02111-1307, USA.
17 #
18 # Jabber
19 # Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/
20 #
21 ##############################################################################
22  
23 package XML::Stream::Parser;
24  
25 =head1 NAME
26  
27 XML::Stream::Parser - SAX XML Parser for XML Streams
28  
29 =head1 SYNOPSIS
30  
31 Light weight XML parser that builds XML::Parser::Tree objects from the
32 incoming stream and passes them to a function to tell whoever is using
33 it that there are new packets.
34  
35 =head1 DESCRIPTION
36  
37 This module provides a very light weight parser
38  
39 =head1 METHODS
40  
41 =head1 EXAMPLES
42  
43 =head1 AUTHOR
44  
45 By Ryan Eatmon in January of 2001 for http://jabber.org/
46  
47 Currently maintained by Darian Anthony Patrick.
48  
49 =head1 COPYRIGHT
50  
51 Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/
52  
53 This module licensed under the LGPL, version 2.1.
54  
55 =cut
56  
57 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 12 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 12 $VERSION = "1.23_06";
62  
63 12 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 12 ▶use XML::Stream::Tree;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 12 ▶use XML::Stream::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 12 ▶use XML::Stream::Tools;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 sub new
70 {
71 11 ▶ my $class = shift;
Subroutine new: called CC=8 SCAR=20.8
Pod undocumented
72  
73 11 my $self = { };
74  
75 11 bless($self, $class);
76  
77 11 my %args;
78 11 ▶ while($#_ >= 0) { $args{ lc pop(@_) } = pop(@_); }
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ >= 0) 24 11 35
79  
80 11 $self->{PARSING} = 0;
81 11 $self->{DOC} = 0;
82 11 $self->{XML} = "";
83 11 $self->{CNAME} = ();
84 11 $self->{CURR} = 0;
85  
86 11 ▶ $args{nonblocking} = 0 unless exists($args{nonblocking});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"nonblocking"} 6 5 11
87  
88 11 $self->{NONBLOCKING} = delete($args{nonblocking});
89 11 XML::Stream::Tools::setup_debug($self, %args);
90  
91 11 ▶ $self->{SID} = exists($args{sid}) ? $args{sid} : "__xmlstream__:sid";
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'sid'} ? : 5 6 11
92  
93 11 ▶ $self->{STYLE} = (exists($args{style}) ? lc($args{style}) : "tree");
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'style'} ? : 9 2 11
94 11 ▶ $self->{DTD} = (exists($args{dtd}) ? lc($args{dtd}) : 0);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'dtd'} ? : 0 11 11
95  
96 11 my $weak = $self;
97 11 weaken $weak;
98 11 ▶ if ($self->{STYLE} eq "tree")
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'STYLE'} eq 'tree') { } 6 5 11
elsif ($self->{'STYLE'} eq 'node') { } 5 0 5
99 {
100 6 ▶ $self->{HANDLER}->{startDocument} = sub{ $weak->startDocument(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
101 6 ▶ $self->{HANDLER}->{endDocument} = sub{ $weak->endDocument(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
102 6 ▶ $self->{HANDLER}->{startElement} = sub{ &XML::Stream::Tree::_handle_element(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
103 6 ▶ $self->{HANDLER}->{endElement} = sub{ &XML::Stream::Tree::_handle_close(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
104 6 ▶ $self->{HANDLER}->{characters} = sub{ &XML::Stream::Tree::_handle_cdata(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
105 }
106 elsif ($self->{STYLE} eq "node")
107 {
108 5 ▶ $self->{HANDLER}->{startDocument} = sub{ $weak->startDocument(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
109 5 ▶ $self->{HANDLER}->{endDocument} = sub{ $weak->endDocument(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
110 5 ▶ $self->{HANDLER}->{startElement} = sub{ &XML::Stream::Node::_handle_element(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
111 5 ▶ $self->{HANDLER}->{endElement} = sub{ &XML::Stream::Node::_handle_close(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
112 5 ▶ $self->{HANDLER}->{characters} = sub{ &XML::Stream::Node::_handle_cdata(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
113 }
114 11 $self->setHandlers(%{$args{handlers}});
115  
116 11 $self->{XMLONHOLD} = "";
117  
118 11 return $self;
119 }
120  
121  
122 ###########################################################################
123 #
124 # debug - prints the arguments to the debug log if debug is turned on.
125 #
126 ###########################################################################
127 sub debug
128 {
129 2010 ▶ return if ($_[1] > $_[0]->{DEBUGLEVEL});
Subroutine debug: called CC=4 SCAR=26.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] > $_[0]{"DEBUGLEVEL"} 2010 0 2010
130 0 my $self = shift;
131 0 my ($limit,@args) = @_;
132 0 ▶ return if ($self->{DEBUGFILE} eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUGFILE"} eq "" 0 0 0
133 0 my $fh = $self->{DEBUGFILE};
134 0 ▶ if ($self->{DEBUGTIME} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUGTIME"} == 1) 0 0 0
135 {
136 0 my ($sec,$min,$hour) = localtime(time);
137 0 print $fh sprintf("[%02d:%02d:%02d] ",$hour,$min,$sec);
138 }
139 0 print $fh "XML::Stream::Parser: $self->{STYLE}: @args\n";
140 }
141  
142  
143 sub setSID
144 {
145 5 ▶ my $self = shift;
Subroutine setSID: called CC=1 SCAR=0.0
Pod undocumented
146 5 my $sid = shift;
147 5 $self->{SID} = $sid;
148 }
149  
150  
151 sub getSID
152 {
153 1663 ▶ my $self = shift;
Subroutine getSID: called CC=1 SCAR=0.0
Pod undocumented
154 1663 return $self->{SID};
155 }
156  
157  
158 sub setHandlers
159 {
160 16 ▶ my $self = shift;
Subroutine setHandlers: called CC=2 SCAR=6.9
Pod undocumented
161 16 my (%handlers) = @_;
162  
163 16 foreach my $handler (keys(%handlers))
164 {
165 30 $self->{HANDLER}->{$handler} = $handlers{$handler};
166 }
167 }
168  
169  
170 sub parse
171 {
172 15 ▶ my $self = shift;
Subroutine parse: called CC=29 SCAR=35.1
Pod undocumented
173 15 my $xml = shift;
174  
175 15 ▶ return unless defined($xml);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xml 0 15 15
176 15 ▶ return if ($xml eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $xml eq "" 4 11 15
177  
178 11 ▶ if ($self->{XMLONHOLD} ne "")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"XMLONHOLD"} ne "") 0 11 11
179 {
180 0 $self->{XML} = $self->{XMLONHOLD};
181 0 $self->{XMLONHOLD} = "";
182 }
183  
184 # XXX change this to not use regex?
185 11 ▶ while($xml =~ s/<\!--.*?-->//gs) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($xml =~ s/<\!--.*?-->//gs) 8 11 19
186  
187 11 $self->{XML} .= $xml;
188  
189 11 ▶ return if ($self->{PARSING} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PARSING"} == 1 0 11 11
190  
191 11 $self->{PARSING} = 1;
192  
193 11 ▶ if(!$self->{DOC} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"DOC"} == 1) 11 0 11
194 {
195 11 my $start = index($self->{XML},"<");
196  
197 11 ▶ if ((substr($self->{XML},$start,3) eq "<?x") ||
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{"XML"}, $start, 3) eq "<?x" or substr($self->{"XML"}, $start, 3) eq "<?X") 1 10 11
Condition66%2/3
substr($self->{"XML"}, $start, 3) eq "<?x" or substr($self->{"XML"}, $start, 3) eq "<?X"
l!l&&r!l&&!r
1010
MC/DC50%1/2
substr($self->{"XML"}, $start, 3) eq "<?x" or substr($self->{"XML"}, $start, 3) eq "<?X"
substr($self->{"XML"}, $start, 3) eq "<?x" substr($self->{"XML"}, $start, 3) eq "<?X"
Truth table66%2/3
A or B
A= substr($self->{"XML"}, $start, 3) eq "<?x"B= substr($self->{"XML"}, $start, 3) eq "<?X"
ABresult
1X1
011
000
198 (substr($self->{XML},$start,3) eq "<?X"))
199 {
200 1 my $close = index($self->{XML},"?>");
201 1 ▶ if ($close == -1)
Branch: 1 branch
BranchTrueFalseTotal
if ($close == -1) 0 1 1
202 {
203 0 $self->{PARSING} = 0;
204 0 return;
205 }
206 1 $self->{XML} = substr($self->{XML},$close+2,length($self->{XML})-$close-2);
207 }
208  
209 11 &{$self->{HANDLER}->{startDocument}}($self);
210 11 $self->{DOC} = 1;
211 }
212  
213 11 while(1)
214 {
215 1623 ▶ if (length($self->{XML}) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"XML"} == 0) 1 1622 1623
216 {
217 1 $self->{PARSING} = 0;
218 1 return $self->returnData(0);
219 }
220 1622 my $eclose = -1;
221 $eclose = index($self->{XML},"</".$self->{CNAME}->[$self->{CURR}].">")
222 1622 ▶ if ($#{$self->{CNAME}} > -1);
Branch: 1 branch
BranchTrueFalseTotal
if $#{$$self{"CNAME"};} > -1 1611 11 1622
223  
224 1622 ▶ if ($eclose == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($eclose == 0) 443 1179 1622
225 {
226 443 $self->{XML} = substr($self->{XML},length($self->{CNAME}->[$self->{CURR}])+3,length($self->{XML})-length($self->{CNAME}->[$self->{CURR}])-3);
227  
228 443 ▶ $self->{PARSING} = 0 if ($self->{NONBLOCKING} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NONBLOCKING"} == 1 0 443 443
229 443 my $weak = $self;
230 443 weaken $weak;
231 443 &{$self->{HANDLER}->{endElement}}($weak, $weak->{CNAME}->[$weak->{CURR}]);
232 443 ▶ $self->{PARSING} = 1 if ($self->{NONBLOCKING} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NONBLOCKING"} == 1 0 443 443
233  
234 443 $self->{CURR}--;
235 443 ▶ if ($self->{CURR} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CURR"} == 0) 10 433 443
236 {
237 10 $self->{DOC} = 0;
238 10 $self->{PARSING} = 0;
239 10 &{$self->{HANDLER}->{endDocument}}($self);
240 10 return $self->returnData(0);
241 }
242 433 next;
243 }
244  
245 1179 my $estart = index($self->{XML},"<");
246 1179 my $cdatastart = index($self->{XML},"<![CDATA[");
247 1179 ▶ if (($estart == 0) && ($cdatastart != 0))
Branch: 1 branch
BranchTrueFalseTotal
if ($estart == 0 and $cdatastart != 0) 485 694 1179
Condition100%3/3
$estart == 0 and $cdatastart != 0
!ll&&!rl&&r
6868485
MC/DC100%2/2
$estart == 0 and $cdatastart != 0
$estart == 0 $cdatastart != 0
Truth table100%3/3
A and B
A= $estart == 0B= $cdatastart != 0
ABresult
0X0
100
111
248 {
249 485 my $close = index($self->{XML},">");
250 485 ▶ if ($close == -1)
Branch: 1 branch
BranchTrueFalseTotal
if ($close == -1) 0 485 485
251 {
252 0 $self->{PARSING} = 0;
253 0 return $self->returnData(0);
254 }
255 485 my $empty = (substr($self->{XML},$close-1,1) eq "/");
256 485 ▶ my $starttag = substr($self->{XML},1,$close-($empty ? 2 : 1));
Branch: 1 branch
BranchTrueFalseTotal
$empty ? : 41 444 485
257 485 my $nextspace = index($starttag," ");
258 485 my $attribs;
259 my $name;
260 485 ▶ if ($nextspace != -1)
Branch: 1 branch
BranchTrueFalseTotal
if ($nextspace != -1) { } 133 352 485
261 {
262 133 $name = substr($starttag,0,$nextspace);
263 133 $attribs = substr($starttag,$nextspace+1,length($starttag)-$nextspace-1);
264 }
265 else
266 {
267 352 $name = $starttag;
268 }
269  
270 485 my %attribs = $self->attribution($attribs);
271 485 ▶ if (($self->{DTD} == 1) && (exists($attribs{xmlns})))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DTD"} == 1 and exists $attribs{"xmlns"}) 0 485 485
Condition33%1/3
$self->{"DTD"} == 1 and exists $attribs{"xmlns"}
!ll&&!rl&&r
48500
MC/DC0%0/2
$self->{"DTD"} == 1 and exists $attribs{"xmlns"}
$self->{"DTD"} == 1 exists $attribs{"xmlns"}
Truth table33%1/3
A and B
A= $self->{"DTD"} == 1B= exists $attribs{"xmlns"}
ABresult
0X0
100
111
272 {
273 }
274  
275 485 my $weak = $self;
276 485 weaken $weak;
277 485 &{$self->{HANDLER}->{startElement}}($weak, $name,%attribs);
278  
279 485 ▶ if($empty == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($empty == 1) { } 41 444 485
280 {
281 41 &{$self->{HANDLER}->{endElement}}($weak, $name);
282 }
283 else
284 {
285 444 $self->{CURR}++;
286 444 $self->{CNAME}->[$self->{CURR}] = $name;
287 }
288
289 485 $self->{XML} = substr($self->{XML},$close+1,length($self->{XML})-$close-1);
290 485 next;
291 }
292  
293 694 ▶ if ($cdatastart == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($cdatastart == 0) 8 686 694
294 {
295 8 my $cdataclose = index($self->{XML},"]]>");
296 8 ▶ if ($cdataclose == -1)
Branch: 1 branch
BranchTrueFalseTotal
if ($cdataclose == -1) 0 8 8
297 {
298 0 $self->{PARSING} = 0;
299 0 return $self->returnData(0);
300 }
301
302 8 &{$self->{HANDLER}->{characters}}($self,substr($self->{XML},9,$cdataclose-9));
303
304 8 $self->{XML} = substr($self->{XML},$cdataclose+3,length($self->{XML})-$cdataclose-3);
305 8 next;
306 }
307  
308 686 ▶ if ($estart == -1)
Branch: 2 branches
BranchTrueFalseTotal
if ($estart == -1) { } 0 686 686
elsif ($cdatastart == -1 or $cdatastart > $estart) { } 686 0 686
309 {
310 0 $self->{XMLONHOLD} = $self->{XML};
311 0 $self->{XML} = "";
312 }
313 ▶ elsif (($cdatastart == -1) || ($cdatastart > $estart))
Condition66%2/3
$cdatastart == -1 or $cdatastart > $estart
l!l&&r!l&&!r
146720
MC/DC0%0/2
$cdatastart == -1 or $cdatastart > $estart
$cdatastart == -1 $cdatastart > $estart
Truth table66%2/3
A or B
A= $cdatastart == -1B= $cdatastart > $estart
ABresult
1X1
011
000
314 {
315 686 &{$self->{HANDLER}->{characters}}($self,$self->entityCheck(substr($self->{XML},0,$estart)));
316 686 $self->{XML} = substr($self->{XML},$estart,length($self->{XML})-$estart);
317 }
318 }
319 }
320  
321  
322 sub attribution
323 {
324 485 ▶ my $self = shift;
Subroutine attribution: called CC=11 SCAR=24.2
Pod undocumented
325 485 my $str = shift;
326  
327 485 ▶ $str = "" unless defined($str);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 352 133 485
328  
329 485 my %attribs;
330  
331 485 while(1)
332 {
333 644 my $eq = index($str,"=");
334 644 ▶ if((length($str) == 0) || ($eq == -1))
Branch: 1 branch
BranchTrueFalseTotal
if (length $str == 0 or $eq == -1) 485 159 644
Condition66%2/3
length $str == 0 or $eq == -1
l!l&&r!l&&!r
4850159
MC/DC50%1/2
length $str == 0 or $eq == -1
length $str == 0 $eq == -1
Truth table66%2/3
A or B
A= length $str == 0B= $eq == -1
ABresult
1X1
011
000
335 {
336 485 return %attribs;
337 }
338  
339 159 my $ids;
340 my $id;
341 159 my $id1 = index($str,"\'");
342 159 my $id2 = index($str,"\"");
343 159 ▶ if((($id1 < $id2) && ($id1 != -1)) || ($id2 == -1))
Branch: 1 branch
BranchTrueFalseTotal
if ($id1 < $id2 and $id1 != -1 or $id2 == -1) { } 156 3 159
Condition100%6/6
$id1 < $id2 and $id1 != -1 or $id2 == -1
l!l&&r!l&&!r
21543
$id1 < $id2 and $id1 != -1
!ll&&!rl&&r
15612
MC/DC100%3/3
$id1 < $id2 and $id1 != -1 or $id2 == -1
$id1 < $id2 $id1 != -1 $id2 == -1
Truth table80%4/5
A and B or C
A= $id1 < $id2B= $id1 != -1C= $id2 == -1
ABCresult
11X1
0X11
1011
0X00
1000
344 {
345 156 $ids = $id1;
346 156 $id = "\'";
347 }
348 else {
349 3 ▶ if((($id2 < $id1) && ($id1 == -1)) || ($id2 != -1))
Branch: 1 branch
BranchTrueFalseTotal
if ($id2 < $id1 and $id1 == -1 or $id2 != -1) 3 0 3
Condition50%3/6
$id2 < $id1 and $id1 == -1 or $id2 != -1
l!l&&r!l&&!r
030
$id2 < $id1 and $id1 == -1
!ll&&!rl&&r
120
MC/DC0%0/3
$id2 < $id1 and $id1 == -1 or $id2 != -1
$id2 < $id1 $id1 == -1 $id2 != -1
Truth table40%2/5
A and B or C
A= $id2 < $id1B= $id1 == -1C= $id2 != -1
ABCresult
11X1
0X11
1011
0X00
1000
350 {
351 3 $ids = $id2;
352 3 $id = "\"";
353 }
354 }
355  
356 159 my $nextid = index($str,$id,$ids+1);
357 159 my $val = substr($str,$ids+1,$nextid-$ids-1);
358 159 my $key = substr($str,0,$eq);
359  
360 159 ▶ while($key =~ s/\s//) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ s/\s//) 26 159 185
361  
362 159 $attribs{$key} = $self->entityCheck($val);
363 159 $str = substr($str,$nextid+1,length($str)-$nextid-1);
364 }
365  
366 0 return %attribs;
367 }
368  
369  
370 sub entityCheck
371 {
372 845 ▶ my $self = shift;
Subroutine entityCheck: called CC=6 SCAR=19.1
Pod undocumented
373 845 my $str = shift;
374  
375 845 ▶ while($str =~ s/\&lt\;/\</) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\&lt\;/</) 0 845 845
376 845 ▶ while($str =~ s/\&gt\;/\>/) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\&gt\;/>/) 0 845 845
377 845 ▶ while($str =~ s/\&quot\;/\"/) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\&quot\;/"/) 0 845 845
378 845 ▶ while($str =~ s/\&apos\;/\'/) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\&apos\;/'/) 0 845 845
379 845 ▶ while($str =~ s/\&amp\;/\&/) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\&amp\;/&/) 0 845 845
380  
381 845 return $str;
382 }
383  
384  
385 sub parsefile
386 {
387 4 ▶ my $self = shift;
Subroutine parsefile: called CC=2 SCAR=6.9
Pod undocumented
388 4 my $fileName = shift;
389  
390 4 open(FILE,"<",$fileName);
391 4 my $file;
392 4 ▶ while(<FILE>) { $file .= $_; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 268 4 272
393 4 $self->parse($file);
394 4 close(FILE);
395  
396 4 return $self->returnData();
397 }
398  
399  
400 sub returnData
401 {
402 15 ▶ my $self = shift;
Subroutine returnData: called CC=8 SCAR=20.8
Pod undocumented
403 15 my $clearData = shift;
404 15 ▶ $clearData = 1 unless defined($clearData);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $clearData 4 11 15
405  
406 15 my $sid = $self->{SID};
407  
408 15 ▶ if ($self->{STYLE} eq "tree")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STYLE"} eq "tree") 8 7 15
409 {
410 8 ▶ return unless exists($self->{SIDS}->{$sid}->{tree});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"SIDS"}{$sid}{"tree"} 2 6 8
411 6 my @tree = @{$self->{SIDS}->{$sid}->{tree}};
412 6 ▶ delete($self->{SIDS}->{$sid}->{tree}) if ($clearData == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $clearData == 1 2 4 6
413 6 return ( \@tree );
414 }
415 7 ▶ if ($self->{STYLE} eq "node")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STYLE"} eq "node") 7 0 7
416 {
417 7 ▶ return unless exists($self->{SIDS}->{$sid}->{node});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"SIDS"}{$sid}{"node"} 3 4 7
418 4 my $node = $self->{SIDS}->{$sid}->{node}->[0];
419 4 ▶ delete($self->{SIDS}->{$sid}->{node}) if ($clearData == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $clearData == 1 2 2 4
420 4 return $node;
421 }
422 }
423  
424  
425 sub startDocument
426 {
427 11 ▶ my $self = shift;
Subroutine startDocument: called CC=1 SCAR=0.0
Pod undocumented
428 }
429  
430  
431 sub endDocument
432 {
433 10 ▶ my $self = shift;
Subroutine endDocument: called CC=1 SCAR=0.0
Pod undocumented
434 }
435  
436  
437 sub startElement
438 {
439 0 ▶ my $self = shift;
Subroutine startElement: not called CC=4 SCAR=30.0
Pod undocumented
440 0 my ($sax, $tag, %att) = @_;
441  
442 0 ▶ return unless ($self->{DOC} == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DOC"} == 1 0 0 0
443  
444 0 ▶ if ($self->{STYLE} eq "debug")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'STYLE'} eq 'debug') { } 0 0 0
445 {
446 0 print "$self->{DEBUGHEADER} \\\\ (",join(" ",%att),")\n";
447 0 $self->{DEBUGHEADER} .= $tag." ";
448 }
449 else
450 {
451 0 my @NEW;
452 0 ▶ if($#{$self->{TREE}} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{'TREE'};} < 0) { } 0 0 0
453 {
454 0 push @{$self->{TREE}}, $tag;
455 }
456 else
457 {
458 0 push @{ $self->{TREE}[ $#{$self->{TREE}}]}, $tag;
459 }
460 0 push @NEW, \%att;
461 0 push @{$self->{TREE}}, \@NEW;
462 }
463 }
464  
465  
466 sub characters
467 {
468 0 ▶ my $self = shift;
Subroutine characters: not called CC=6 SCAR=37.4
Pod undocumented
469 0 my ($sax, $cdata) = @_;
470  
471 0 ▶ return unless ($self->{DOC} == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DOC"} == 1 0 0 0
472  
473 0 ▶ if ($self->{STYLE} eq "debug")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'STYLE'} eq 'debug') { } 0 0 0
474 {
475 0 my $str = $cdata;
476 0 $str =~ s/\n/\#10\;/g;
477 0 print "$self->{DEBUGHEADER} || $str\n";
478 }
479 else
480 {
481 0 ▶ return if ($#{$self->{TREE}} == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $#{$$self{"TREE"};} == -1 0 0 0
482  
483 0 my $pos = $#{$self->{TREE}};
484  
485 0 ▶ if ($pos > 0 && $self->{TREE}[$pos - 1] eq "0")
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 0 and $self->{'TREE'}[$pos - 1] eq '0') { } 0 0 0
Condition0%0/3
$pos > 0 and $self->{"TREE"}[$pos - 1] eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$pos > 0 and $self->{"TREE"}[$pos - 1] eq 0
$pos > 0 $self->{"TREE"}[$pos - 1] eq 0
Truth table0%0/3
A and B
A= $pos > 0B= $self->{"TREE"}[$pos - 1] eq 0
ABresult
0X0
100
111
486 {
487 0 $self->{TREE}[$pos - 1] .= $cdata;
488 }
489 else
490 {
491 0 push @{$self->{TREE}[$#{$self->{TREE}}]}, 0;
492 0 push @{$self->{TREE}[$#{$self->{TREE}}]}, $cdata;
493 }
494 }
495 }
496  
497  
498 sub endElement
499 {
500 0 ▶ my $self = shift;
Subroutine endElement: not called CC=5 SCAR=34.0
Pod undocumented
501 0 my ($sax, $tag) = @_;
502  
503 0 ▶ return unless ($self->{DOC} == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DOC"} == 1 0 0 0
504  
505 0 ▶ if ($self->{STYLE} eq "debug")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'STYLE'} eq 'debug') { } 0 0 0
506 {
507 0 $self->{DEBUGHEADER} =~ s/\S+\ $//;
508 0 print "$self->{DEBUGHEADER} //\n";
509 }
510 else
511 {
512 0 my $CLOSED = pop @{$self->{TREE}};
513  
514 0 ▶ if($#{$self->{TREE}} < 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{'TREE'};} < 1) { } 0 0 0
515 {
516 0 push @{$self->{TREE}}, $CLOSED;
517  
518 0 ▶ if($self->{TREE}->[0] eq "stream:error")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"TREE"}[0] eq "stream:error") 0 0 0
519 {
520 0 $self->{STREAMERROR} = $self->{TREE}[1]->[2];
521 }
522 }
523 else
524 {
525 0 push @{$self->{TREE}[$#{$self->{TREE}}]}, $CLOSED;
526 }
527 }
528 }
529  
530  
531 12 1;
« blib/lib/XML/Stream/Tools.pm ↑ Summary blib/lib/XML/Stream/XPath/Op.pm »