blib/lib/XML/LibXML.pm

filter: Statementstmt 83.6% 984 / 1177 Branchbran 64.2% 339 / 528 Conditioncond 65.6% 82 / 125 MC/DCmcdc 43.2% 32 / 74 Subroutinesub 81.0% 167 / 206 Podpod 0.0% 0 / 46 totaltotal 74.4% 1604 / 2156 CC 316 SCAR 19.3
CC
316
Cov
77%
VERSION
30.0
import
29.0
_html_options
22.5
CRAP 6.9
« blib/lib/XML/LibXML/Reader.pm ↑ Summary blib/lib/XML/LibXML/Error.pm »
1 # $Id$
2 #
3 #
4 # This is free software, you may use it and distribute it under the same terms as
5 # Perl itself.
6 #
7 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
8 #
9 #
10  
11 package XML::LibXML;
12  
13 69 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 69 use vars qw($VERSION $ABI_VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS
17 $skipDTD $skipXMLDeclaration $setTagCompression
18 $MatchCB $ReadCB $OpenCB $CloseCB %PARSER_FLAGS
19 $XML_LIBXML_PARSE_DEFAULTS
20 69 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 69 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 69 ▶use constant XML_XMLNS_NS => 'http://www.w3.org/2000/xmlns/';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 69 ▶use constant XML_XML_NS => 'http://www.w3.org/XML/1998/namespace';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 69 ▶use XML::LibXML::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 69 ▶use XML::LibXML::NodeList;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 69 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 69 ▶use IO::Handle; # for FH reads called as methods
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 BEGIN {
32 69 ▶$VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE
Subroutine BEGIN: called CC=1 SCAR=0.7
33 69 $ABI_VERSION = 2;
34 69 require Exporter;
35 69 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 69 @ISA = qw(Exporter);
37  
38 69 ▶use vars qw($__PROXY_NODE_REGISTRY $__threads_shared $__PROXY_NODE_REGISTRY_MUTEX $__loaded);
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 sub VERSION {
41 0 ▶ my $class = shift;
Subroutine VERSION: not called CC=5 SCAR=34.0
Pod undocumented
42 0 my ($caller) = caller;
43 0 my $req_abi = $ABI_VERSION;
44 0 ▶ if (UNIVERSAL::can($caller,'REQUIRE_XML_LIBXML_ABI_VERSION')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::can($caller, 'REQUIRE_XML_LIBXML_ABI_VERSION')) { } 0 0 0
elsif ($caller eq 'XML::LibXSLT') { } 0 0 0
45 0 $req_abi = $caller->REQUIRE_XML_LIBXML_ABI_VERSION();
46 } elsif ($caller eq 'XML::LibXSLT') {
47 # XML::LibXSLT without REQUIRE_XML_LIBXML_ABI_VERSION is an old and incompatible version
48 0 $req_abi = 1;
49 }
50 0 ▶ unless ($req_abi == $ABI_VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req_abi == $XML::LibXML::ABI_VERSION) 0 0 0
51 0 ▶ my $ver = @_ ? ' '.$_[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
52 0 die ("This version of $caller requires XML::LibXML$ver (ABI $req_abi), which is incompatible with currently installed XML::LibXML $VERSION (ABI $ABI_VERSION). Please upgrade $caller, XML::LibXML, or both!");
53 }
54 0 return $class->UNIVERSAL::VERSION(@_)
55 }
56  
57 #-------------------------------------------------------------------------#
58 # export information #
59 #-------------------------------------------------------------------------#
60 69 %EXPORT_TAGS = (
61 all => [qw(
62 XML_ELEMENT_NODE
63 XML_ATTRIBUTE_NODE
64 XML_TEXT_NODE
65 XML_CDATA_SECTION_NODE
66 XML_ENTITY_REF_NODE
67 XML_ENTITY_NODE
68 XML_PI_NODE
69 XML_COMMENT_NODE
70 XML_DOCUMENT_NODE
71 XML_DOCUMENT_TYPE_NODE
72 XML_DOCUMENT_FRAG_NODE
73 XML_NOTATION_NODE
74 XML_HTML_DOCUMENT_NODE
75 XML_DTD_NODE
76 XML_ELEMENT_DECL
77 XML_ATTRIBUTE_DECL
78 XML_ENTITY_DECL
79 XML_NAMESPACE_DECL
80 XML_XINCLUDE_END
81 XML_XINCLUDE_START
82 encodeToUTF8
83 decodeFromUTF8
84 XML_XMLNS_NS
85 XML_XML_NS
86 )],
87 libxml => [qw(
88 XML_ELEMENT_NODE
89 XML_ATTRIBUTE_NODE
90 XML_TEXT_NODE
91 XML_CDATA_SECTION_NODE
92 XML_ENTITY_REF_NODE
93 XML_ENTITY_NODE
94 XML_PI_NODE
95 XML_COMMENT_NODE
96 XML_DOCUMENT_NODE
97 XML_DOCUMENT_TYPE_NODE
98 XML_DOCUMENT_FRAG_NODE
99 XML_NOTATION_NODE
100 XML_HTML_DOCUMENT_NODE
101 XML_DTD_NODE
102 XML_ELEMENT_DECL
103 XML_ATTRIBUTE_DECL
104 XML_ENTITY_DECL
105 XML_NAMESPACE_DECL
106 XML_XINCLUDE_END
107 XML_XINCLUDE_START
108 )],
109 encoding => [qw(
110 encodeToUTF8
111 decodeFromUTF8
112 )],
113 ns => [qw(
114 XML_XMLNS_NS
115 XML_XML_NS
116 )],
117 );
118  
119 @EXPORT_OK = (
120 69 @{$EXPORT_TAGS{all}},
121 );
122  
123 @EXPORT = (
124 69 @{$EXPORT_TAGS{all}},
125 );
126  
127 #-------------------------------------------------------------------------#
128 # initialization of the global variables #
129 #-------------------------------------------------------------------------#
130 69 $skipDTD = 0;
131 69 $skipXMLDeclaration = 0;
132 69 $setTagCompression = 0;
133  
134 69 $MatchCB = undef;
135 69 $ReadCB = undef;
136 69 $OpenCB = undef;
137 69 $CloseCB = undef;
138  
139 # if ($threads::threads) {
140 # our $__THREADS_TID = 0;
141 # eval q{
142 # use threads::shared;
143 # our $__PROXY_NODE_REGISTRY_MUTEX :shared = 0;
144 # };
145 # die $@ if $@;
146 # }
147 #-------------------------------------------------------------------------#
148 # bootstrapping #
149 #-------------------------------------------------------------------------#
150 69 XSLoader::load( 'XML::LibXML', $VERSION );
151 69 undef &AUTOLOAD;
152  
153 69 *encodeToUTF8 = \&XML::LibXML::Common::encodeToUTF8;
154 69 *decodeFromUTF8 = \&XML::LibXML::Common::decodeFromUTF8;
155  
156 } # BEGIN
157  
158  
159 #-------------------------------------------------------------------------#
160 # libxml2 node names (see also XML::LibXML::Common #
161 #-------------------------------------------------------------------------#
162 69 ▶use constant XML_ELEMENT_NODE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
163 69 ▶use constant XML_ATTRIBUTE_NODE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
164 69 ▶use constant XML_TEXT_NODE => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
165 69 ▶use constant XML_CDATA_SECTION_NODE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
166 69 ▶use constant XML_ENTITY_REF_NODE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
167 69 ▶use constant XML_ENTITY_NODE => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
168 69 ▶use constant XML_PI_NODE => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
169 69 ▶use constant XML_COMMENT_NODE => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
170 69 ▶use constant XML_DOCUMENT_NODE => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
171 69 ▶use constant XML_DOCUMENT_TYPE_NODE => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
172 69 ▶use constant XML_DOCUMENT_FRAG_NODE => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
173 69 ▶use constant XML_NOTATION_NODE => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
174 69 ▶use constant XML_HTML_DOCUMENT_NODE => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
175 69 ▶use constant XML_DTD_NODE => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
176 69 ▶use constant XML_ELEMENT_DECL => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
177 69 ▶use constant XML_ATTRIBUTE_DECL => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
178 69 ▶use constant XML_ENTITY_DECL => 17;
Subroutine BEGIN: called CC=1 SCAR=0.0
179 69 ▶use constant XML_NAMESPACE_DECL => 18;
Subroutine BEGIN: called CC=1 SCAR=0.0
180 69 ▶use constant XML_XINCLUDE_START => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
181 69 ▶use constant XML_XINCLUDE_END => 20;
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183  
184 sub import {
185 223 ▶ my $package=shift;
Subroutine import: called CC=8 SCAR=33.7
186 223 ▶ if (grep /^:threads_shared$/, @_) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep /^:threads_shared$/, @_) { } 0 223 223
elsif (defined $XML::LibXML::__loaded) { } 85 138 223
187 0 require threads;
188 0 ▶ if (!defined($__threads_shared)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $XML::LibXML::__threads_shared) { } 0 0 0
elsif (not $XML::LibXML::__threads_shared) { } 0 0 0
189 0 ▶ if (INIT_THREAD_SUPPORT()) {
Branch: 1 branch
BranchTrueFalseTotal
if (INIT_THREAD_SUPPORT()) { } 0 0 0
190 0 eval q{
191 use threads::shared;
192 share($__PROXY_NODE_REGISTRY_MUTEX);
193 };
194 0 ▶ if ($@) { # something went wrong
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
195 0 DISABLE_THREAD_SUPPORT(); # leave the library in a usable state
196 0 die $@; # and die
197 }
198 0 $__PROXY_NODE_REGISTRY = XML::LibXML::HashTable->new();
199 0 $__threads_shared=1;
200 } else {
201 0 croak("XML::LibXML or Perl compiled without ithread support!");
202 }
203 } elsif (!$__threads_shared) {
204 0 croak("XML::LibXML already loaded without thread support. Too late to enable thread support!");
205 }
206 } elsif (defined $XML::LibXML::__loaded) {
207 85 ▶ $__threads_shared=0 if not defined $__threads_shared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::LibXML::__threads_shared 67 18 85
208 }
209 223 __PACKAGE__->export_to_level(1,$package,grep !/^:threads(_shared)?$/,@_);
210 }
211  
212 sub threads_shared_enabled {
213 0 ▶ return $__threads_shared ? 1 : 0;
Subroutine threads_shared_enabled: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
214 }
215  
216 # if ($threads::threads) {
217 # our $__PROXY_NODE_REGISTRY = XML::LibXML::HashTable->new();
218 # }
219  
220 #-------------------------------------------------------------------------#
221 # test exact version (up to patch-level) #
222 #-------------------------------------------------------------------------#
223 {
224 69 my ($runtime_version) = LIBXML_RUNTIME_VERSION() =~ /^(\d+)/;
225 69 ▶ if ( $runtime_version < LIBXML_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runtime_version < LIBXML_VERSION()) 0 69 69
226 0 warn "Warning: XML::LibXML compiled against libxml2 ".LIBXML_VERSION.
227 ", but runtime libxml2 is older $runtime_version\n";
228 }
229 }
230  
231  
232 #-------------------------------------------------------------------------#
233 # parser flags #
234 #-------------------------------------------------------------------------#
235  
236 # Copied directly from http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
237 use constant {
238 69 XML_PARSE_RECOVER => 1, # recover on errors
239 XML_PARSE_NOENT => 2, # substitute entities
240 XML_PARSE_DTDLOAD => 4, # load the external subset
241 XML_PARSE_DTDATTR => 8, # default DTD attributes
242 XML_PARSE_DTDVALID => 16, # validate with the DTD
243 XML_PARSE_NOERROR => 32, # suppress error reports
244 XML_PARSE_NOWARNING => 64, # suppress warning reports
245 XML_PARSE_PEDANTIC => 128, # pedantic error reporting
246 XML_PARSE_NOBLANKS => 256, # remove blank nodes
247 XML_PARSE_SAX1 => 512, # use the SAX1 interface internally
248 XML_PARSE_XINCLUDE => 1024, # Implement XInclude substitution
249 XML_PARSE_NONET => 2048, # Forbid network access
250 XML_PARSE_NODICT => 4096, # Do not reuse the context dictionary
251 XML_PARSE_NSCLEAN => 8192, # remove redundant namespaces declarations
252 XML_PARSE_NOCDATA => 16384, # merge CDATA as text nodes
253 XML_PARSE_NOXINCNODE => 32768, # do not generate XINCLUDE START/END nodes
254 XML_PARSE_COMPACT => 65536, # compact small text nodes; no modification of the tree allowed afterwards
255 # (will possibly crash if you try to modify the tree)
256 XML_PARSE_OLD10 => 131072, # parse using XML-1.0 before update 5
257 XML_PARSE_NOBASEFIX => 262144, # do not fixup XINCLUDE xml#base uris
258 XML_PARSE_HUGE => 524288, # relax any hardcoded limit from the parser
259 XML_PARSE_OLDSAX => 1048576, # parse using SAX2 interface from before 2.7.0
260 HTML_PARSE_RECOVER => (1<<0), # suppress error reports
261 HTML_PARSE_NOERROR => (1<<5), # suppress error reports
262 69 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
263  
264 69 $XML_LIBXML_PARSE_DEFAULTS = ( XML_PARSE_NODICT );
265  
266 # this hash is made global so that applications can add names for new
267 # libxml2 parser flags as temporary workaround
268  
269 69 %PARSER_FLAGS = (
270 recover => XML_PARSE_RECOVER,
271 expand_entities => XML_PARSE_NOENT,
272 load_ext_dtd => XML_PARSE_DTDLOAD,
273 complete_attributes => XML_PARSE_DTDATTR,
274 validation => XML_PARSE_DTDVALID,
275 suppress_errors => XML_PARSE_NOERROR,
276 suppress_warnings => XML_PARSE_NOWARNING,
277 pedantic_parser => XML_PARSE_PEDANTIC,
278 no_blanks => XML_PARSE_NOBLANKS,
279 expand_xinclude => XML_PARSE_XINCLUDE,
280 xinclude => XML_PARSE_XINCLUDE,
281 no_network => XML_PARSE_NONET,
282 clean_namespaces => XML_PARSE_NSCLEAN,
283 no_cdata => XML_PARSE_NOCDATA,
284 no_xinclude_nodes => XML_PARSE_NOXINCNODE,
285 old10 => XML_PARSE_OLD10,
286 no_base_fix => XML_PARSE_NOBASEFIX,
287 huge => XML_PARSE_HUGE,
288 oldsax => XML_PARSE_OLDSAX,
289 );
290  
291 69 my %OUR_FLAGS = (
292 recover => 'XML_LIBXML_RECOVER',
293 line_numbers => 'XML_LIBXML_LINENUMBERS',
294 URI => 'XML_LIBXML_BASE_URI',
295 base_uri => 'XML_LIBXML_BASE_URI',
296 gdome => 'XML_LIBXML_GDOME',
297 ext_ent_handler => 'ext_ent_handler',
298 );
299  
300 sub _parser_options {
301 119 ▶ my ($self, $opts) = @_;
Subroutine _parser_options: called CC=8 SCAR=21.2
302  
303 # currently dictionaries break XML::LibXML memory management
304  
305 119 my $flags;
306  
307 119 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 25 94 119
308 25 ▶ $flags = ($self->{XML_LIBXML_PARSER_OPTIONS}||0);
Condition50%1/2
$self->{'XML_LIBXML_PARSER_OPTIONS'} || 0
l!l
250
MC/DC0%0/1
$self->{'XML_LIBXML_PARSER_OPTIONS'} || 0
$self->{'XML_LIBXML_PARSER_OPTIONS'}
Truth table50%1/2
A
A= $self->{'XML_LIBXML_PARSER_OPTIONS'}
Aresult
11
00
309 } else {
310 94 $flags = $XML_LIBXML_PARSE_DEFAULTS; # safety precaution
311 }
312  
313 119 my ($key, $value);
314 119 ▶ while (($key,$value) = each %$opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$opts) 178 119 297
315 178 my $f = $PARSER_FLAGS{ $key };
316 178 ▶ if (defined $f) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $f) { } 99 79 178
elsif ($key eq 'set_parser_flags') { } 0 79 79
elsif ($key eq 'unset_parser_flags') { } 0 79 79
317 99 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 71 28 99
318 71 $flags |= $f
319 } else {
320 28 $flags &= ~$f;
321 }
322 } elsif ($key eq 'set_parser_flags') { # this can be used to pass flags XML::LibXML does not yet know about
323 0 $flags |= $value;
324 } elsif ($key eq 'unset_parser_flags') {
325 0 $flags &= ~$value;
326 }
327  
328 }
329 119 return $flags;
330 }
331  
332 69 my %compatibility_flags = (
333 XML_LIBXML_VALIDATION => 'validation',
334 XML_LIBXML_EXPAND_ENTITIES => 'expand_entities',
335 XML_LIBXML_PEDANTIC => 'pedantic_parser',
336 XML_LIBXML_NONET => 'no_network',
337 XML_LIBXML_EXT_DTD => 'load_ext_dtd',
338 XML_LIBXML_COMPLETE_ATTR => 'complete_attributes',
339 XML_LIBXML_EXPAND_XINCLUDE => 'expand_xinclude',
340 XML_LIBXML_NSCLEAN => 'clean_namespaces',
341 XML_LIBXML_KEEP_BLANKS => 'keep_blanks',
342 XML_LIBXML_LINENUMBERS => 'line_numbers',
343 );
344  
345 #-------------------------------------------------------------------------#
346 # parser constructor #
347 #-------------------------------------------------------------------------#
348  
349  
350 sub new {
351 183 ▶ my $class = shift;
Subroutine new: called CC=13 SCAR=26.0
Pod undocumented
352 183 my $self = bless {
353 }, $class;
354 183 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 43 140 183
355 43 my %opts = ();
356 43 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 25 18 43
357 25 %opts = %{$_[0]};
358 } else {
359 # old interface
360 18 my %args = @_;
361 %opts=(
362 map {
363 18 ▶ (($compatibility_flags{ $_ }||$_) => $args{ $_ })
Branch: 1 branch
BranchTrueFalseTotal
$compatibility_flags{$_} or $_ 65 0 65
364 } keys %args
365 );
366 }
367 # parser flags
368 43 ▶ $opts{no_blanks} = !$opts{keep_blanks} if exists($opts{keep_blanks}) and !exists($opts{no_blanks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"keep_blanks"} and not exists $opts{"no_blanks"} 0 43 43
Condition33%1/3
exists $opts{"keep_blanks"} and not exists $opts{"no_blanks"}
!ll&&!rl&&r
4300
MC/DC0%0/2
exists $opts{"keep_blanks"} and not exists $opts{"no_blanks"}
exists $opts{"keep_blanks"} not exists $opts{"no_blanks"}
Truth table33%1/3
A and not(B)
A= exists $opts{"keep_blanks"}B= not exists $opts{"no_blanks"}
ABresult
0X0
100
111
369 43 ▶ $opts{load_ext_dtd} = $opts{expand_entities} if exists($opts{expand_entities}) and !exists($opts{load_ext_dtd});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"expand_entities"} and not exists $opts{"load_ext_dtd"} 13 30 43
Condition100%3/3
exists $opts{"expand_entities"} and not exists $opts{"load_ext_dtd"}
!ll&&!rl&&r
26413
MC/DC100%2/2
exists $opts{"expand_entities"} and not exists $opts{"load_ext_dtd"}
exists $opts{"expand_entities"} not exists $opts{"load_ext_dtd"}
Truth table100%3/3
A and not(B)
A= exists $opts{"expand_entities"}B= not exists $opts{"load_ext_dtd"}
ABresult
0X0
100
111
370  
371 43 for (keys %OUR_FLAGS) {
372 258 $self->{$OUR_FLAGS{$_}} = delete $opts{$_};
373 }
374 43 ▶ $class->load_catalog(delete($opts{catalog})) if $opts{catalog};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"catalog"} 1 42 43
375  
376 43 $self->{XML_LIBXML_PARSER_OPTIONS} = XML::LibXML->_parser_options(\%opts);
377  
378 # store remaining unknown options directly in $self
379 43 for (keys %opts) {
380 99 ▶ $self->{$_}=$opts{$_} unless exists $PARSER_FLAGS{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $XML::LibXML::PARSER_FLAGS{$_} 13 86 99
381 }
382 } else {
383 140 $self->{XML_LIBXML_PARSER_OPTIONS} = $XML_LIBXML_PARSE_DEFAULTS;
384 }
385 183 ▶ if ( defined $self->{Handler} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Handler"}) 0 183 183
386 0 $self->set_handler( $self->{Handler} );
387 }
388  
389 183 $self->{_State_} = 0;
390 183 return $self;
391 }
392  
393 sub _clone {
394 9 ▶ my ($self)=@_;
Subroutine _clone: called CC=1 SCAR=0.0
395 my $new = ref($self)->new({
396 recover => $self->{XML_LIBXML_RECOVER},
397 line_numbers => $self->{XML_LIBXML_LINENUMBERS},
398 base_uri => $self->{XML_LIBXML_BASE_URI},
399 gdome => $self->{XML_LIBXML_GDOME},
400 9 });
401 # The parser options may contain some options that were zeroed from the
402 # defaults so set_parser_flags won't work here. We need to assign them
403 # explicitly.
404 9 $new->{XML_LIBXML_PARSER_OPTIONS} = $self->{XML_LIBXML_PARSER_OPTIONS};
405 9 $new->input_callbacks($self->input_callbacks());
406 9 return $new;
407 }
408  
409 #-------------------------------------------------------------------------#
410 # Threads support methods #
411 #-------------------------------------------------------------------------#
412  
413 # threads doc says CLONE's API may change in future, which would break
414 # an XS method prototype
415 sub CLONE {
416 0 ▶ if ($XML::LibXML::__threads_shared) {
Subroutine CLONE: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($XML::LibXML::__threads_shared) 0 0 0
417 0 XML::LibXML::_CLONE( $_[0] );
418 }
419 }
420  
421 sub CLONE_SKIP {
422 0 ▶ return $XML::LibXML::__threads_shared ? 0 : 1;
Subroutine CLONE_SKIP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
423 }
424  
425 sub __proxy_registry {
426 0 ▶ my ($class)=caller;
Subroutine __proxy_registry: not called CC=1 SCAR=6.9
427 0 die "This version of $class uses API of XML::LibXML 1.66 which is not compatible with XML::LibXML $VERSION. Please upgrade $class!\n";
428 }
429  
430 #-------------------------------------------------------------------------#
431 # DOM Level 2 document constructor #
432 #-------------------------------------------------------------------------#
433  
434 sub createDocument {
435 13 ▶ my $self = shift;
Subroutine createDocument: called CC=4 SCAR=13.9
Pod undocumented
436 13 ▶ if (!@_ or $_[0] =~ m/^\d\.\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_ or $_[0] =~ /^\d\.\d$/) { } 10 3 13
Condition100%3/3
not @_ or $_[0] =~ /^\d\.\d$/
l!l&&r!l&&!r
913
MC/DC100%2/2
not @_ or $_[0] =~ /^\d\.\d$/
not @_ $_[0] =~ /^\d\.\d$/
Truth table100%3/3
not(A) or B
A= not @_B= $_[0] =~ /^\d\.\d$/
ABresult
1X1
011
000
437 # for backward compatibility
438 10 return XML::LibXML::Document->new(@_);
439 }
440 else {
441 # DOM API: createDocument(namespaceURI, qualifiedName, doctype?)
442 3 my $doc = XML::LibXML::Document-> new;
443 3 my $el = $doc->createElementNS(shift, shift);
444 3 $doc->setDocumentElement($el);
445 3 ▶ $doc->setExternalSubset(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
446 3 return $doc;
447 }
448 }
449  
450 #-------------------------------------------------------------------------#
451 # callback functions #
452 #-------------------------------------------------------------------------#
453  
454 sub externalEntityLoader(&)
455 {
456 1 ▶ return _externalEntityLoader($_[0]);
Subroutine externalEntityLoader: called CC=1 SCAR=0.0
Pod undocumented
457 }
458  
459 sub input_callbacks {
460 26 ▶ my $self = shift;
Subroutine input_callbacks: called CC=2 SCAR=6.9
Pod undocumented
461 26 my $icbclass = shift;
462  
463 26 ▶ if ( defined $icbclass ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $icbclass) 10 16 26
464 10 $self->{XML_LIBXML_CALLBACK_STACK} = $icbclass;
465 }
466 26 return $self->{XML_LIBXML_CALLBACK_STACK};
467 }
468  
469 sub match_callback {
470 688 ▶ my $self = shift;
Subroutine match_callback: called CC=4 SCAR=15.5
Pod undocumented
471 688 ▶ if ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 688 0 688
472 688 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 4 684 688
473 4 $self->{XML_LIBXML_MATCH_CB} = shift;
474 4 $self->{XML_LIBXML_CALLBACK_STACK} = undef;
475 }
476 688 return $self->{XML_LIBXML_MATCH_CB};
477 }
478 else {
479 0 ▶ $MatchCB = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
480 0 return $MatchCB;
481 }
482 }
483  
484 sub read_callback {
485 688 ▶ my $self = shift;
Subroutine read_callback: called CC=4 SCAR=15.5
Pod undocumented
486 688 ▶ if ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 688 0 688
487 688 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 4 684 688
488 4 $self->{XML_LIBXML_READ_CB} = shift;
489 4 $self->{XML_LIBXML_CALLBACK_STACK} = undef;
490 }
491 688 return $self->{XML_LIBXML_READ_CB};
492 }
493 else {
494 0 ▶ $ReadCB = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
495 0 return $ReadCB;
496 }
497 }
498  
499 sub close_callback {
500 688 ▶ my $self = shift;
Subroutine close_callback: called CC=4 SCAR=15.5
Pod undocumented
501 688 ▶ if ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 688 0 688
502 688 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 4 684 688
503 4 $self->{XML_LIBXML_CLOSE_CB} = shift;
504 4 $self->{XML_LIBXML_CALLBACK_STACK} = undef;
505 }
506 688 return $self->{XML_LIBXML_CLOSE_CB};
507 }
508 else {
509 0 ▶ $CloseCB = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
510 0 return $CloseCB;
511 }
512 }
513  
514 sub open_callback {
515 688 ▶ my $self = shift;
Subroutine open_callback: called CC=4 SCAR=15.5
Pod undocumented
516 688 ▶ if ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 688 0 688
517 688 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 4 684 688
518 4 $self->{XML_LIBXML_OPEN_CB} = shift;
519 4 $self->{XML_LIBXML_CALLBACK_STACK} = undef;
520 }
521 688 return $self->{XML_LIBXML_OPEN_CB};
522 }
523 else {
524 0 ▶ $OpenCB = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
525 0 return $OpenCB;
526 }
527 }
528  
529 sub callbacks {
530 0 ▶ my $self = shift;
Subroutine callbacks: not called CC=4 SCAR=30.0
Pod undocumented
531 0 ▶ if ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
532 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
533 0 my ($match, $open, $read, $close) = @_;
534 0 @{$self}{qw(XML_LIBXML_MATCH_CB XML_LIBXML_OPEN_CB XML_LIBXML_READ_CB XML_LIBXML_CLOSE_CB)} = ($match, $open, $read, $close);
535 0 $self->{XML_LIBXML_CALLBACK_STACK} = undef;
536 }
537 else {
538 0 return @{$self}{qw(XML_LIBXML_MATCH_CB XML_LIBXML_OPEN_CB XML_LIBXML_READ_CB XML_LIBXML_CLOSE_CB)};
539 }
540 }
541 else {
542 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
543 0 ( $MatchCB, $OpenCB, $ReadCB, $CloseCB ) = @_;
544 }
545 else {
546 0 return ( $MatchCB, $OpenCB, $ReadCB, $CloseCB );
547 }
548 }
549 }
550  
551 #-------------------------------------------------------------------------#
552 # internal member variable manipulation #
553 #-------------------------------------------------------------------------#
554 sub __parser_option {
555 691 ▶ my ($self, $opt) = @_;
Subroutine __parser_option: called CC=4 SCAR=13.9
556 691 ▶ if (@_>2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) { } 119 572 691
557 119 ▶ if ($_[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 66 53 119
558 66 $self->{XML_LIBXML_PARSER_OPTIONS} |= $opt;
559 66 return 1;
560 } else {
561 53 $self->{XML_LIBXML_PARSER_OPTIONS} &= ~$opt;
562 53 return 0;
563 }
564 } else {
565 572 ▶ return ($self->{XML_LIBXML_PARSER_OPTIONS} & $opt) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'XML_LIBXML_PARSER_OPTIONS'} & $opt ? : 93 479 572
566 }
567 }
568  
569 sub option_exists {
570 24 ▶ my ($self,$name)=@_;
Subroutine option_exists: called CC=3 SCAR=11.0
Pod undocumented
571 24 ▶ return ($PARSER_FLAGS{$name} || $OUR_FLAGS{$name}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::PARSER_FLAGS{$name} || $OUR_FLAGS{$name} ? : 23 1 24
Condition100%3/3
$XML::LibXML::PARSER_FLAGS{$name} or $OUR_FLAGS{$name}
l!l&&r!l&&!r
1941
MC/DC100%2/2
$XML::LibXML::PARSER_FLAGS{$name} or $OUR_FLAGS{$name}
$XML::LibXML::PARSER_FLAGS{$name} $OUR_FLAGS{$name}
Truth table100%3/3
A or B
A= $XML::LibXML::PARSER_FLAGS{$name}B= $OUR_FLAGS{$name}
ABresult
1X1
011
000
572 }
573 sub get_option {
574 171 ▶ my ($self,$name)=@_;
Subroutine get_option: called CC=3 SCAR=11.6
Pod undocumented
575 171 my $flag = $OUR_FLAGS{$name};
576 171 ▶ return $self->{$flag} if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 34 137 171
577 137 $flag = $PARSER_FLAGS{$name};
578 137 ▶ return $self->__parser_option($flag) if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 137 0 137
579 0 warn "XML::LibXML::get_option: unknown parser option $name\n";
580 0 return undef;
581 }
582 sub set_option {
583 58 ▶ my ($self,$name,$value)=@_;
Subroutine set_option: called CC=3 SCAR=11.6
Pod undocumented
584 58 my $flag = $OUR_FLAGS{$name};
585 58 ▶ return ($self->{$flag}=$value) if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 19 39 58
586 39 $flag = $PARSER_FLAGS{$name};
587 39 ▶ return $self->__parser_option($flag,$value) if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 39 0 39
588 0 warn "XML::LibXML::get_option: unknown parser option $name\n";
589 0 return undef;
590 }
591 sub set_options {
592 1 ▶ my $self=shift;
Subroutine set_options: called CC=5 SCAR=20.2
Pod undocumented
593 1 my $opts;
594 1 ▶ if (@_==1 and ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 1 0 1
elsif (@_ % 2 == 0) { } 0 0 0
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
595 1 $opts = $_[0];
596 } elsif (@_ % 2 == 0) {
597 0 $opts={@_};
598 } else {
599 0 croak("Odd number of elements passed to set_options");
600 }
601 1 $self->set_option($_=>$opts->{$_}) foreach keys %$opts;
602 1 return;
603 }
604  
605 sub validation {
606 10 ▶ my $self = shift;
Subroutine validation: called CC=1 SCAR=0.0
Pod undocumented
607 10 return $self->__parser_option(XML_PARSE_DTDVALID,@_);
608 }
609  
610 sub recover {
611 67 ▶ my $self = shift;
Subroutine recover: called CC=2 SCAR=6.9
Pod undocumented
612 67 ▶ if (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 5 62 67
613 5 $self->{XML_LIBXML_RECOVER} = $_[0];
614 5 $self->__parser_option(XML_PARSE_RECOVER,@_);
615 }
616 67 return $self->{XML_LIBXML_RECOVER};
617 }
618  
619 sub recover_silently {
620 33 ▶ my $self = shift;
Subroutine recover_silently: called CC=5 SCAR=16.1
Pod undocumented
621 33 my $arg = shift;
622 33 ▶ if ( defined($arg) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 2 31 33
623 {
624 2 ▶ $self->recover(($arg == 1) ? 2 : $arg);
Branch: 1 branch
BranchTrueFalseTotal
$arg == 1 ? : 1 1 2
625 }
626 33 ▶ return (($self->recover()||0) == 2) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($self->recover || 0) == 2 ? : 3 30 33
Condition100%2/2
$self->recover || 0
l!l
1914
MC/DC100%1/1
$self->recover || 0
$self->recover
Truth table100%2/2
A
A= $self->recover
Aresult
11
00
627 }
628  
629 sub expand_entities {
630 17 ▶ my $self = shift;
Subroutine expand_entities: called CC=3 SCAR=11.0
Pod undocumented
631 17 ▶ if (scalar(@_) and $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ and $_[0]) 7 10 17
Condition100%3/3
scalar @_ and $_[0]
!ll&&!rl&&r
377
MC/DC100%2/2
scalar @_ and $_[0]
scalar @_ $_[0]
Truth table100%3/3
A and B
A= scalar @_B= $_[0]
ABresult
0X0
100
111
632 7 return $self->__parser_option(XML_PARSE_NOENT | XML_PARSE_DTDLOAD,1);
633 }
634 10 return $self->__parser_option(XML_PARSE_NOENT,@_);
635 }
636  
637 sub keep_blanks {
638 37 ▶ my $self = shift;
Subroutine keep_blanks: called CC=4 SCAR=13.9
Pod undocumented
639 37 my @args; # we have to negate the argument and return negated value, since
640 # the actual flag is no_blanks
641 37 ▶ if (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 7 30 37
642 7 ▶ @args=($_[0] ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 3 4 7
643 }
644 37 ▶ return $self->__parser_option(XML_PARSE_NOBLANKS,@args) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->__parser_option(256, @args) ? : 5 32 37
645 }
646  
647 sub pedantic_parser {
648 37 ▶ my $self = shift;
Subroutine pedantic_parser: called CC=1 SCAR=0.0
Pod undocumented
649 37 return $self->__parser_option(XML_PARSE_PEDANTIC,@_);
650 }
651  
652 sub line_numbers {
653 9 ▶ my $self = shift;
Subroutine line_numbers: called CC=2 SCAR=6.9
Pod undocumented
654 9 ▶ $self->{XML_LIBXML_LINENUMBERS} = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 4 5 9
655 9 return $self->{XML_LIBXML_LINENUMBERS};
656 }
657  
658 sub no_network {
659 35 ▶ my $self = shift;
Subroutine no_network: called CC=1 SCAR=0.0
Pod undocumented
660 35 return $self->__parser_option(XML_PARSE_NONET,@_);
661 }
662  
663 sub load_ext_dtd {
664 21 ▶ my $self = shift;
Subroutine load_ext_dtd: called CC=1 SCAR=0.0
Pod undocumented
665 21 return $self->__parser_option(XML_PARSE_DTDLOAD,@_);
666 }
667  
668 sub complete_attributes {
669 11 ▶ my $self = shift;
Subroutine complete_attributes: called CC=1 SCAR=0.0
Pod undocumented
670 11 return $self->__parser_option(XML_PARSE_DTDATTR,@_);
671 }
672  
673 sub expand_xinclude {
674 334 ▶ my $self = shift;
Subroutine expand_xinclude: called CC=1 SCAR=0.0
Pod undocumented
675 334 return $self->__parser_option(XML_PARSE_XINCLUDE,@_);
676 }
677  
678 sub base_uri {
679 4 ▶ my $self = shift;
Subroutine base_uri: called CC=2 SCAR=6.9
Pod undocumented
680 4 ▶ $self->{XML_LIBXML_BASE_URI} = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 2 2 4
681 4 return $self->{XML_LIBXML_BASE_URI};
682 }
683  
684 sub gdome_dom {
685 0 ▶ my $self = shift;
Subroutine gdome_dom: not called CC=2 SCAR=17.9
Pod undocumented
686 0 ▶ $self->{XML_LIBXML_GDOME} = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
687 0 return $self->{XML_LIBXML_GDOME};
688 }
689  
690 sub clean_namespaces {
691 8 ▶ my $self = shift;
Subroutine clean_namespaces: called CC=1 SCAR=0.0
Pod undocumented
692 8 return $self->__parser_option(XML_PARSE_NSCLEAN,@_);
693 }
694  
695 #-------------------------------------------------------------------------#
696 # set the optional SAX(2) handler #
697 #-------------------------------------------------------------------------#
698 sub set_handler {
699 82 ▶ my $self = shift;
Subroutine set_handler: called CC=2 SCAR=6.9
Pod undocumented
700 82 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) { } 42 40 82
701 42 $self->{HANDLER} = $_[0];
702  
703 42 $self->{SAX_ELSTACK} = [];
704 42 $self->{SAX} = {State => 0};
705 }
706 else {
707 # undef SAX handling
708 40 $self->{SAX_ELSTACK} = [];
709 40 delete $self->{HANDLER};
710 40 delete $self->{SAX};
711 }
712 }
713  
714 #-------------------------------------------------------------------------#
715 # helper functions #
716 #-------------------------------------------------------------------------#
717 sub _auto_expand {
718 313 ▶ my ( $self, $result, $uri ) = @_;
Subroutine _auto_expand: called CC=4 SCAR=13.9
719  
720 313 ▶ $result->setBaseURI( $uri ) if defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri 4 309 313
721  
722 313 ▶ if ( $self->expand_xinclude ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expand_xinclude) 16 297 313
723 16 $self->{_State_} = 1;
724 16 eval { $self->processXIncludes($result); };
725 16 my $err = $@;
726 16 $self->{_State_} = 0;
727 16 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 1 15 16
728 1 $self->_cleanup_callbacks();
729 1 $result = undef;
730 1 croak $err;
731 }
732 }
733 312 return $result;
734 }
735  
736 sub _init_callbacks {
737 684 ▶ my $self = shift;
Subroutine _init_callbacks: called CC=2 SCAR=6.9
738 684 my $icb = $self->{XML_LIBXML_CALLBACK_STACK};
739 684 ▶ unless ( defined $icb ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $icb) 161 523 684
740 161 $self->{XML_LIBXML_CALLBACK_STACK} = XML::LibXML::InputCallback->new();
741 161 $icb = $self->{XML_LIBXML_CALLBACK_STACK};
742 }
743  
744 684 $icb->init_callbacks($self);
745 }
746  
747 sub _cleanup_callbacks {
748 684 ▶ my $self = shift;
Subroutine _cleanup_callbacks: called CC=1 SCAR=0.0
749 684 $self->{XML_LIBXML_CALLBACK_STACK}->cleanup_callbacks();
750 }
751  
752 sub __read {
753 23 ▶ read($_[0], $_[1], $_[2]);
Subroutine __read: called CC=1 SCAR=0.0
754 }
755  
756 sub __write {
757 1 ▶ if ( ref( $_[0] ) ) {
Subroutine __write: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 1 0 1
758 1 $_[0]->write( $_[1], $_[2] );
759 }
760 else {
761 0 $_[0]->write( $_[1] );
762 }
763 }
764  
765 sub load_xml {
766 16 ▶ my $class_or_self = shift;
Subroutine load_xml: called CC=7 SCAR=19.6
Pod undocumented
767 16 ▶ my %args = map { ref($_) eq 'HASH' ? (%$_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 34 34
768  
769 16 my $URI = delete($args{URI});
770 16 ▶ $URI = "$URI" if defined $URI; # stringify in case it is an URI object
Branch: 1 branch
BranchTrueFalseTotal
if defined $URI 0 16 16
771 16 my $parser;
772 16 ▶ if (ref($class_or_self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class_or_self) { } 3 13 16
773 3 $parser = $class_or_self->_clone();
774 3 $parser->{XML_LIBXML_PARSER_OPTIONS} = $parser->_parser_options(\%args);
775 } else {
776 13 $parser = $class_or_self->new(\%args);
777 }
778 16 my $dom;
779 16 ▶ if ( defined $args{location} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $args{'location'}) { } 1 15 16
elsif (defined $args{'string'}) { } 13 2 15
elsif (defined $args{'IO'}) { } 2 0 2
780 1 $dom = $parser->parse_file( "$args{location}" );
781 }
782 elsif ( defined $args{string} ) {
783 13 $dom = $parser->parse_string( $args{string}, $URI );
784 }
785 elsif ( defined $args{IO} ) {
786 2 $dom = $parser->parse_fh( $args{IO}, $URI );
787 }
788 else {
789 0 croak("XML::LibXML->load: specify location, string, or IO");
790 }
791 16 return $dom;
792 }
793  
794 sub load_html {
795 6 ▶ my ($class_or_self) = shift;
Subroutine load_html: called CC=7 SCAR=23.0
Pod undocumented
796 6 ▶ my %args = map { ref($_) eq 'HASH' ? (%$_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 14 14
797 6 my $URI = delete($args{URI});
798 6 ▶ $URI = "$URI" if defined $URI; # stringify in case it is an URI object
Branch: 1 branch
BranchTrueFalseTotal
if defined $URI 0 6 6
799 6 my $parser;
800 6 ▶ if (ref($class_or_self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class_or_self) { } 6 0 6
801 6 $parser = $class_or_self->_clone();
802 } else {
803 0 $parser = $class_or_self->new();
804 }
805 6 my $dom;
806 6 ▶ if ( defined $args{location} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $args{'location'}) { } 0 6 6
elsif (defined $args{'string'}) { } 6 0 6
elsif (defined $args{'IO'}) { } 0 0 0
807 0 $dom = $parser->parse_html_file( "$args{location}", \%args );
808 }
809 elsif ( defined $args{string} ) {
810 6 $dom = $parser->parse_html_string( $args{string}, \%args );
811 }
812 elsif ( defined $args{IO} ) {
813 0 $dom = $parser->parse_html_fh( $args{IO}, \%args );
814 }
815 else {
816 0 croak("XML::LibXML->load: specify location, string, or IO");
817 }
818 6 return $dom;
819 }
820  
821 #-------------------------------------------------------------------------#
822 # parsing functions #
823 #-------------------------------------------------------------------------#
824 # all parsing functions handle normal as SAX parsing at the same time.
825 # note that SAX parsing is handled incomplete! use XML::LibXML::SAX for
826 # complete parsing sequences
827 #-------------------------------------------------------------------------#
828 sub parse_string {
829 368 ▶ my $self = shift;
Subroutine parse_string: called CC=10 SCAR=23.0
Pod undocumented
830 368 ▶ croak("parse_string is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 368 368
831 368 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 368 368
832  
833 368 ▶ unless ( defined $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0] and length $_[0]) 8 360 368
Condition100%3/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
44360
MC/DC100%2/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
834 8 croak("Empty String");
835 }
836  
837 360 $self->{_State_} = 1;
838 360 my $result;
839  
840 360 $self->_init_callbacks();
841  
842 360 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 37 323 360
843 37 my $string = shift;
844 37 $self->{SAX_ELSTACK} = [];
845 37 eval { $result = $self->_parse_sax_string($string); };
846 37 my $err = $@;
847 37 $self->{_State_} = 0;
848 37 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 3 34 37
849 3 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 1 2 3
850 3 $self->_cleanup_callbacks();
851 3 croak $err;
852 }
853 }
854 else {
855 323 eval { $result = $self->_parse_string( @_ ); };
856  
857 323 my $err = $@;
858 323 $self->{_State_} = 0;
859 323 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 77 246 323
860 77 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 77 77
861 77 $self->_cleanup_callbacks();
862 77 croak $err;
863 }
864  
865 246 $result = $self->_auto_expand( $result, $self->{XML_LIBXML_BASE_URI} );
866 }
867 279 $self->_cleanup_callbacks();
868  
869 279 return $result;
870 }
871  
872 sub parse_fh {
873 9 ▶ my $self = shift;
Subroutine parse_fh: called CC=8 SCAR=24.7
Pod undocumented
874 9 ▶ croak("parse_fh is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 9 9
875 9 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 9 9
876 9 $self->{_State_} = 1;
877 9 my $result;
878  
879 9 $self->_init_callbacks();
880  
881 9 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 0 9 9
882 0 $self->{SAX_ELSTACK} = [];
883 0 eval { $self->_parse_sax_fh( @_ ); };
884 0 my $err = $@;
885 0 $self->{_State_} = 0;
886 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
887 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
888 0 $self->_cleanup_callbacks();
889 0 croak $err;
890 }
891 }
892 else {
893 9 eval { $result = $self->_parse_fh( @_ ); };
894 9 my $err = $@;
895 9 $self->{_State_} = 0;
896 9 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 3 6 9
897 3 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 2 1 3
898 3 $self->_cleanup_callbacks();
899 3 croak $err;
900 }
901  
902 6 $result = $self->_auto_expand( $result, $self->{XML_LIBXML_BASE_URI} );
903 }
904  
905 6 $self->_cleanup_callbacks();
906  
907 6 return $result;
908 }
909  
910 sub parse_file {
911 68 ▶ my $self = shift;
Subroutine parse_file: called CC=8 SCAR=21.4
Pod undocumented
912 68 ▶ croak("parse_file is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 68 68
913 68 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 68 68
914  
915 68 $self->{_State_} = 1;
916 68 my $result;
917  
918 68 $self->_init_callbacks();
919  
920 68 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 1 67 68
921 1 $self->{SAX_ELSTACK} = [];
922 1 eval { $self->_parse_sax_file( @_ ); };
923 1 my $err = $@;
924 1 $self->{_State_} = 0;
925 1 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 1 1
926 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
927 0 $self->_cleanup_callbacks();
928 0 croak $err;
929 }
930 }
931 else {
932 67 eval { $result = $self->_parse_file(@_); };
933 67 my $err = $@;
934 67 $self->{_State_} = 0;
935 67 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 6 61 67
936 6 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 1 5 6
937 6 $self->_cleanup_callbacks();
938 6 croak $err;
939 }
940  
941 61 $result = $self->_auto_expand( $result );
942 }
943 62 $self->_cleanup_callbacks();
944  
945 62 return $result;
946 }
947  
948 sub parse_xml_chunk {
949 75 ▶ my $self = shift;
Subroutine parse_xml_chunk: called CC=9 SCAR=22.0
Pod undocumented
950 # max 2 parameter:
951 # 1: the chunk
952 # 2: the encoding of the string
953 75 ▶ croak("parse_xml_chunk is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 75 75
954 75 ▶ croak("parse already in progress") if $self->{_State_}; my $result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 75 75
955  
956 75 ▶ unless ( defined $_[0] and length $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0] and length $_[0]) 3 72 75
Condition100%3/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
1272
MC/DC100%2/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
957 3 croak("Empty String");
958 }
959  
960 72 $self->{_State_} = 1;
961  
962 72 $self->_init_callbacks();
963  
964 72 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 29 43 72
965 29 eval {
966 29 $self->_parse_sax_xml_chunk( @_ );
967  
968 # this is required for XML::GenericChunk.
969 # in normal case is_filter is not defined, an thus the parsing
970 # will be terminated. in case of a SAX filter the parsing is not
971 # finished at that state. therefore we must not reset the parsing
972 29 ▶ unless ( $self->{IS_FILTER} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"IS_FILTER"}) 27 2 29
973 27 $result = $self->{HANDLER}->end_document();
974 }
975 };
976 }
977 else {
978 43 eval { $result = $self->_parse_xml_chunk( @_ ); };
979 }
980  
981 72 $self->_cleanup_callbacks();
982  
983 72 my $err = $@;
984 72 $self->{_State_} = 0;
985 72 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 8 64 72
986 8 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 8 8
987 8 croak $err;
988 }
989  
990 64 return $result;
991 }
992  
993 sub parse_balanced_chunk {
994 1 ▶ my $self = shift;
Subroutine parse_balanced_chunk: called CC=3 SCAR=12.0
Pod undocumented
995 1 $self->_init_callbacks();
996 1 my $rv;
997 1 eval {
998 1 $rv = $self->parse_xml_chunk( @_ );
999 };
1000 1 my $err = $@;
1001 1 $self->_cleanup_callbacks();
1002 1 ▶ if ( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 1 1
1003 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1004 0 croak $err;
1005 }
1006 1 return $rv
1007 }
1008  
1009 # java style
1010 sub processXIncludes {
1011 22 ▶ my $self = shift;
Subroutine processXIncludes: called CC=6 SCAR=17.9
Pod undocumented
1012 22 my $doc = shift;
1013 22 my $opts = shift;
1014 22 my $options = $self->_parser_options($opts);
1015 22 ▶ if ( $self->{_State_} != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_State_"} != 1) 6 16 22
1016 6 $self->_init_callbacks();
1017 }
1018 22 my $rv;
1019 22 eval {
1020 22 ▶ $rv = $self->_processXIncludes($doc || " ", $options);
Condition100%2/2
$doc || ' '
l!l
211
MC/DC100%1/1
$doc || ' '
$doc
Truth table100%2/2
A
A= $doc
Aresult
11
00
1021 };
1022 22 my $err = $@;
1023 22 ▶ if ( $self->{_State_} != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_State_"} != 1) 6 16 22
1024 6 $self->_cleanup_callbacks();
1025 }
1026  
1027 22 ▶ if ( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 4 18 22
1028 4 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 2 2 4
1029 4 croak $err;
1030 }
1031 18 return $rv;
1032 }
1033  
1034 # perl style
1035 sub process_xincludes {
1036 0 ▶ my $self = shift;
Subroutine process_xincludes: not called CC=4 SCAR=30.0
Pod undocumented
1037 0 my $doc = shift;
1038 0 my $opts = shift;
1039 0 my $options = $self->_parser_options($opts);
1040  
1041 0 my $rv;
1042 0 $self->_init_callbacks();
1043 0 eval {
1044 0 ▶ $rv = $self->_processXIncludes($doc || " ", $options);
Condition0%0/2
$doc || ' '
l!l
00
MC/DC0%0/1
$doc || ' '
$doc
Truth table0%0/2
A
A= $doc
Aresult
11
00
1045 };
1046 0 my $err = $@;
1047 0 $self->_cleanup_callbacks();
1048 0 ▶ if ( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
1049 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1050 0 croak $@;
1051 }
1052 0 return $rv;
1053 }
1054  
1055 #-------------------------------------------------------------------------#
1056 # HTML parsing functions #
1057 #-------------------------------------------------------------------------#
1058  
1059 sub _html_options {
1060 28 ▶ my ($self,$opts)=@_;
Subroutine _html_options: called CC=20 SCAR=31.1
1061 28 ▶ $opts = {} unless ref $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts 10 18 28
1062 # return (undef,undef) unless ref $opts;
1063 28 my $flags = 0;
1064 {
1065 28 ▶ my $recover = exists $opts->{recover} ? $opts->{recover} : $self->recover;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'recover'} ? : 4 24 28
1066  
1067 28 ▶ if ($recover)
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) 20 8 28
1068 {
1069 20 $flags |= HTML_PARSE_RECOVER;
1070 20 ▶ if ($recover == 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($recover == 2) 4 16 20
1071 {
1072 4 $flags |= HTML_PARSE_NOERROR;
1073 }
1074 }
1075 }
1076  
1077 28 ▶ $flags |= 4 if $opts->{no_defdtd}; # default is ON: injects DTD as needed
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_defdtd"} 1 27 28
1078 28 ▶ $flags |= 32 if exists $opts->{suppress_errors} ? $opts->{suppress_errors} : $self->get_option('suppress_errors');
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts->{"suppress_errors"} ? $opts->{"suppress_errors"} : $self->get_option("suppress_errors") 2 26 28
exists $opts->{'suppress_errors'} ? : 1 27 28
1079 # This is to fix https://rt.cpan.org/Ticket/Display.html?id=58024 :
1080 # <quote>
1081 # In XML::LibXML, warnings are not suppressed when specifying the recover
1082 # or recover_silently flags as per the following excerpt from the manpage:
1083 # </quote>
1084 28 ▶ if ($self->recover_silently)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->recover_silently) 1 27 28
1085 {
1086 1 $flags |= 32;
1087 }
1088 28 ▶ $flags |= 64 if $opts->{suppress_warnings};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"suppress_warnings"} 0 28 28
1089 28 ▶ $flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser;
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts->{"pedantic_parser"} ? $opts->{"pedantic_parser"} : $self->pedantic_parser 0 28 28
exists $opts->{'pedantic_parser'} ? : 0 28 28
1090 28 ▶ $flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks;
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts->{"no_blanks"} ? $opts->{"no_blanks"} : !$self->keep_blanks 0 28 28
exists $opts->{'no_blanks'} ? : 0 28 28
1091 28 ▶ $flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : !$self->no_network;
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts->{"no_network"} ? $opts->{"no_network"} : !$self->no_network 28 0 28
exists $opts->{'no_network'} ? : 0 28 28
1092 28 ▶ $flags |= 16384 if $opts->{no_cdata};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_cdata"} 0 28 28
1093 28 ▶ $flags |= 65536 if $opts->{compact}; # compact small text nodes; no modification
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"compact"} 0 28 28
1094 # of the tree allowed afterwards
1095 # (WILL possibly CRASH IF YOU try to MODIFY THE TREE)
1096 28 ▶ $flags |= 524288 if $opts->{huge}; # relax any hardcoded limit from the parser
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"huge"} 0 28 28
1097 28 ▶ $flags |= 1048576 if $opts->{oldsax}; # parse using SAX2 interface from before 2.7.0
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"oldsax"} 0 28 28
1098  
1099 28 return ($opts->{URI},$opts->{encoding},$flags);
1100 }
1101  
1102 sub parse_html_string {
1103 18 ▶ my ($self,$str,$opts) = @_;
Subroutine parse_html_string: called CC=7 SCAR=22.9
Pod undocumented
1104 18 ▶ croak("parse_html_string is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 18 18
1105 18 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 18 18
1106  
1107 18 ▶ unless ( defined $str and length $str ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $str and length $str) 0 18 18
Condition33%1/3
defined $str and length $str
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $str and length $str
defined $str length $str
Truth table33%1/3
A and B
A= defined $strB= length $str
ABresult
0X0
100
111
1108 0 croak("Empty String");
1109 }
1110 18 $self->{_State_} = 1;
1111 18 my $result;
1112  
1113 18 $self->_init_callbacks();
1114 18 eval {
1115 18 $result = $self->_parse_html_string( $str,
1116 $self->_html_options($opts)
1117 );
1118 };
1119 18 my $err = $@;
1120 18 $self->{_State_} = 0;
1121 18 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 18 18
1122 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1123 0 $self->_cleanup_callbacks();
1124 0 croak $err;
1125 }
1126  
1127 18 $self->_cleanup_callbacks();
1128  
1129 18 return $result;
1130 }
1131  
1132 sub parse_html_file {
1133 6 ▶ my ($self,$file,$opts) = @_;
Subroutine parse_html_file: called CC=5 SCAR=17.8
Pod undocumented
1134 6 ▶ croak("parse_html_file is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 6 6
1135 6 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 6 6
1136 6 $self->{_State_} = 1;
1137 6 my $result;
1138  
1139 6 $self->_init_callbacks();
1140 6 eval { $result = $self->_parse_html_file($file,
1141 $self->_html_options($opts)
1142 ); };
1143 6 my $err = $@;
1144 6 $self->{_State_} = 0;
1145 6 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 6 6
1146 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1147 0 $self->_cleanup_callbacks();
1148 0 croak $err;
1149 }
1150  
1151 6 $self->_cleanup_callbacks();
1152  
1153 6 return $result;
1154 }
1155  
1156 sub parse_html_fh {
1157 4 ▶ my ($self,$fh,$opts) = @_;
Subroutine parse_html_fh: called CC=5 SCAR=17.8
Pod undocumented
1158 4 ▶ croak("parse_html_fh is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 4 4
1159 4 ▶ croak("parse already in progress") if $self->{_State_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_State_"} 0 4 4
1160 4 $self->{_State_} = 1;
1161  
1162 4 my $result;
1163 4 $self->_init_callbacks();
1164 4 eval { $result = $self->_parse_html_fh( $fh,
1165 $self->_html_options($opts)
1166 ); };
1167 4 my $err = $@;
1168 4 $self->{_State_} = 0;
1169 4 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 4 4
1170 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1171 0 $self->_cleanup_callbacks();
1172 0 croak $err;
1173 }
1174 4 $self->_cleanup_callbacks();
1175  
1176 4 return $result;
1177 }
1178  
1179 #-------------------------------------------------------------------------#
1180 # push parser interface #
1181 #-------------------------------------------------------------------------#
1182 sub init_push {
1183 78 ▶ my $self = shift;
Subroutine init_push: called CC=3 SCAR=11.0
Pod undocumented
1184  
1185 78 ▶ if ( defined $self->{CONTEXT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"CONTEXT"}) 1 77 78
1186 1 delete $self->{CONTEXT};
1187 }
1188  
1189 78 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 36 42 78
1190 36 $self->{CONTEXT} = $self->_start_push(1);
1191 }
1192 else {
1193 42 $self->{CONTEXT} = $self->_start_push(0);
1194 }
1195 }
1196  
1197 sub push {
1198 140 ▶ my $self = shift;
Subroutine push: called CC=5 SCAR=17.1
Pod undocumented
1199  
1200 140 $self->_init_callbacks();
1201  
1202 140 ▶ if ( not defined $self->{CONTEXT} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"CONTEXT"}) 36 104 140
1203 36 $self->init_push();
1204 }
1205  
1206 140 eval {
1207 140 foreach ( @_ ) {
1208 140 $self->_push( $self->{CONTEXT}, $_ );
1209 }
1210 };
1211 140 my $err = $@;
1212 140 $self->_cleanup_callbacks();
1213 140 ▶ if ( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 140 140
1214 0 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 0 0
1215 0 croak $err;
1216 }
1217 }
1218  
1219 # this function should be promoted!
1220 # the reason is because libxml2 uses xmlParseChunk() for this purpose!
1221 sub parse_chunk {
1222 202 ▶ my $self = shift;
Subroutine parse_chunk: called CC=5 SCAR=16.1
Pod undocumented
1223 202 my $chunk = shift;
1224 202 my $terminate = shift;
1225  
1226 202 ▶ if ( not defined $self->{CONTEXT} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"CONTEXT"}) 41 161 202
1227 41 $self->init_push();
1228 }
1229  
1230 202 ▶ if ( defined $chunk and length $chunk ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $chunk and length $chunk) 162 40 202
Condition66%2/3
defined $chunk and length $chunk
!ll&&!rl&&r
040162
MC/DC50%1/2
defined $chunk and length $chunk
defined $chunk length $chunk
Truth table66%2/3
A and B
A= defined $chunkB= length $chunk
ABresult
0X0
100
111
1231 162 $self->_push( $self->{CONTEXT}, $chunk );
1232 }
1233  
1234 195 ▶ if ( $terminate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($terminate) 40 155 195
1235 40 return $self->finish_push();
1236 }
1237 }
1238  
1239  
1240 sub finish_push {
1241 77 ▶ my $self = shift;
Subroutine finish_push: called CC=6 SCAR=17.9
Pod undocumented
1242 77 ▶ my $restore = shift || 0;
Condition100%2/2
shift() || 0
l!l
176
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1243 77 ▶ return undef unless defined $self->{CONTEXT};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CONTEXT"} 0 77 77
1244  
1245 77 my $retval;
1246  
1247 77 ▶ if ( defined $self->{SAX} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'SAX'}) { } 36 41 77
1248 36 eval {
1249 36 $self->_end_sax_push( $self->{CONTEXT} );
1250 36 $retval = $self->{HANDLER}->end_document( {} );
1251 };
1252 }
1253 else {
1254 41 eval { $retval = $self->_end_push( $self->{CONTEXT}, $restore ); };
1255 }
1256 77 my $err = $@;
1257 77 delete $self->{CONTEXT};
1258 77 ▶ if ( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 2 75 77
1259 2 ▶ chomp $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 0 2 2
1260 2 croak( $err );
1261 }
1262 75 return $retval;
1263 }
1264  
1265 69 1;
1266  
1267 #-------------------------------------------------------------------------#
1268 # XML::LibXML::Node Interface #
1269 #-------------------------------------------------------------------------#
1270 package XML::LibXML::Node;
1271  
1272 69 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
1273  
1274 use overload
1275 2 ▶ '""' => sub { $_[0]->toString() },
Subroutine __ANON__: called CC=1 SCAR=0.0
1276 848 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
1277 19254 ▶ '0+' => sub { Scalar::Util::refaddr($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1278 69 fallback => 1,
1279 69 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
1280  
1281  
1282 sub CLONE_SKIP {
1283 0 ▶ return $XML::LibXML::__threads_shared ? 0 : 1;
Subroutine CLONE_SKIP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
1284 }
1285  
1286 sub isSupported {
1287 0 ▶ my $self = shift;
Subroutine isSupported: not called CC=2 SCAR=17.9
1288 0 my $feature = shift;
1289 0 ▶ return $self->can($feature) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->can($feature) ? : 0 0 0
1290 }
1291  
1292 0 ▶sub getChildNodes { my $self = shift; return $self->childNodes(); }
Subroutine getChildNodes: not called CC=1 SCAR=6.9
1293  
1294 sub childNodes {
1295 159 ▶ my $self = shift;
Subroutine childNodes: called CC=2 SCAR=6.9
1296 159 my @children = $self->_childNodes(0);
1297 159 ▶ return wantarray ? @children : XML::LibXML::NodeList->new_from_ref(\@children , 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 157 2 159
1298 }
1299  
1300 sub nonBlankChildNodes {
1301 2 ▶ my $self = shift;
Subroutine nonBlankChildNodes: called CC=2 SCAR=7.1
1302 2 my @children = $self->_childNodes(1);
1303 2 ▶ return wantarray ? @children : XML::LibXML::NodeList->new_from_ref(\@children , 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
1304 }
1305  
1306 sub attributes {
1307 51 ▶ my $self = shift;
Subroutine attributes: called CC=2 SCAR=6.9
1308 51 my @attr = $self->_attributes();
1309 51 ▶ return wantarray ? @attr : XML::LibXML::NamedNodeMap->new( @attr );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 49 2 51
1310 }
1311  
1312  
1313 sub findnodes {
1314 66 ▶ my ($node, $xpath) = @_;
Subroutine findnodes: called CC=2 SCAR=6.9
1315 66 my @nodes = $node->_findnodes($xpath);
1316 58 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 44 14 58
1317 44 return @nodes;
1318 }
1319 else {
1320 14 return XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
1321 }
1322 }
1323  
1324 sub exists {
1325 8 ▶ my ($node, $xpath) = @_;
Subroutine exists: called CC=1 SCAR=0.0
1326 8 my (undef, $value) = $node->_find($xpath,1);
1327 8 return $value;
1328 }
1329  
1330 sub findvalue {
1331 20 ▶ my ($node, $xpath) = @_;
Subroutine findvalue: called CC=1 SCAR=0.0
1332 20 my $res;
1333 20 $res = $node->find($xpath);
1334 16 return $res->to_literal->value;
1335 }
1336  
1337 sub findbool {
1338 0 ▶ my ($node, $xpath) = @_;
Subroutine findbool: not called CC=2 SCAR=17.9
1339 0 my ($type, @params) = $node->_find($xpath,1);
1340 0 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 0 0 0
1341 0 return $type->new(@params);
1342 }
1343 0 return undef;
1344 }
1345  
1346 sub find {
1347 46 ▶ my ($node, $xpath) = @_;
Subroutine find: called CC=2 SCAR=7.4
1348 46 my ($type, @params) = $node->_find($xpath,0);
1349 34 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 34 0 34
1350 34 return $type->new(@params);
1351 }
1352 0 return undef;
1353 }
1354  
1355 sub setOwnerDocument {
1356 1 ▶ my ( $self, $doc ) = @_;
Subroutine setOwnerDocument: called CC=1 SCAR=0.0
1357 1 $doc->adoptNode( $self );
1358 }
1359  
1360 sub toStringC14N {
1361 14 ▶ my ($self, $comments, $xpath, $xpc) = @_;
Subroutine toStringC14N: called CC=4 SCAR=13.9
1362 14 ▶ return $self->_toStringC14N( $comments || 0,
Branch: 2 branches
BranchTrueFalseTotal
defined $xpath ? : 2 12 14
defined $xpc ? : 0 14 14
Condition100%2/2
$comments || 0
l!l
212
MC/DC100%1/1
$comments || 0
$comments
Truth table100%2/2
A
A= $comments
Aresult
11
00
1363 (defined $xpath ? $xpath : undef),
1364 0,
1365 undef,
1366 (defined $xpc ? $xpc : undef)
1367 );
1368 }
1369  
1370 {
1371 69 my $C14N_version_1_dot_1_val = 2;
1372  
1373 sub toStringC14N_v1_1 {
1374 0 ▶ my ($self, $comments, $xpath, $xpc) = @_;
Subroutine toStringC14N_v1_1: not called CC=4 SCAR=30.0
1375  
1376 0 ▶ return $self->_toStringC14N(
Branch: 2 branches
BranchTrueFalseTotal
defined $xpath ? : 0 0 0
defined $xpc ? : 0 0 0
Condition0%0/2
$comments || 0
l!l
00
MC/DC0%0/1
$comments || 0
$comments
Truth table0%0/2
A
A= $comments
Aresult
11
00
1377 $comments || 0,
1378 (defined $xpath ? $xpath : undef),
1379 $C14N_version_1_dot_1_val,
1380 undef,
1381 (defined $xpc ? $xpc : undef)
1382 );
1383 }
1384  
1385 }
1386  
1387 69 sub toStringEC14N {
1388 10 ▶ my ($self, $comments, $xpath, $xpc, $inc_prefix_list) = @_;
Subroutine toStringEC14N: called CC=9 SCAR=23.0
1389 10 ▶ unless (UNIVERSAL::isa($xpc,'XML::LibXML::XPathContext')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($xpc, "XML::LibXML::XPathContext")) 8 2 10
1390 8 ▶ if ($inc_prefix_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inc_prefix_list) { } 0 8 8
1391 0 croak("toStringEC14N: 3rd argument is not an XML::LibXML::XPathContext");
1392 } else {
1393 8 $inc_prefix_list=$xpc;
1394 8 $xpc=undef;
1395 }
1396 }
1397 10 ▶ if (defined($inc_prefix_list) and !UNIVERSAL::isa($inc_prefix_list,'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inc_prefix_list and not UNIVERSAL::isa($inc_prefix_list, "ARRAY")) 0 10 10
Condition66%2/3
defined $inc_prefix_list and not UNIVERSAL::isa($inc_prefix_list, "ARRAY")
!ll&&!rl&&r
370
MC/DC0%0/2
defined $inc_prefix_list and not UNIVERSAL::isa($inc_prefix_list, "ARRAY")
defined $inc_prefix_list not UNIVERSAL::isa($inc_prefix_list, "ARRAY")
Truth table66%2/3
A and not(B)
A= defined $inc_prefix_listB= not UNIVERSAL::isa($inc_prefix_list, "ARRAY")
ABresult
0X0
100
111
1398 0 croak("toStringEC14N: inclusive_prefix_list must be undefined or ARRAY");
1399 }
1400 10 ▶ return $self->_toStringC14N( $comments || 0,
Branch: 3 branches
BranchTrueFalseTotal
defined $xpath ? : 9 1 10
defined $inc_prefix_list ? : 7 3 10
defined $xpc ? : 2 8 10
Condition50%1/2
$comments || 0
l!l
010
MC/DC0%0/1
$comments || 0
$comments
Truth table50%1/2
A
A= $comments
Aresult
11
00
1401 (defined $xpath ? $xpath : undef),
1402 1,
1403 (defined $inc_prefix_list ? $inc_prefix_list : undef),
1404 (defined $xpc ? $xpc : undef)
1405 );
1406 }
1407  
1408 69 *serialize_c14n = \&toStringC14N;
1409 69 *serialize_exc_c14n = \&toStringEC14N;
1410  
1411 69 1;
1412  
1413 #-------------------------------------------------------------------------#
1414 # XML::LibXML::Document Interface #
1415 #-------------------------------------------------------------------------#
1416 package XML::LibXML::Document;
1417  
1418 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1419 69 @ISA = ('XML::LibXML::Node');
1420  
1421 sub actualEncoding {
1422 3 ▶ my $doc = shift;
Subroutine actualEncoding: called CC=3 SCAR=12.5
1423 3 my $enc = $doc->encoding;
1424 3 ▶ return (defined $enc and length $enc) ? $enc : 'UTF-8';
Branch: 1 branch
BranchTrueFalseTotal
defined $enc && length $enc ? : 3 0 3
Condition33%1/3
defined $enc and length $enc
!ll&&!rl&&r
003
MC/DC0%0/2
defined $enc and length $enc
defined $enc length $enc
Truth table33%1/3
A and B
A= defined $encB= length $enc
ABresult
0X0
100
111
1425 }
1426  
1427 sub setDocumentElement {
1428 96 ▶ my $doc = shift;
Subroutine setDocumentElement: called CC=2 SCAR=6.9
1429 96 my $element = shift;
1430  
1431 96 my $oldelem = $doc->documentElement;
1432 96 ▶ if ( defined $oldelem ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldelem) 2 94 96
1433 2 $doc->removeChild($oldelem);
1434 }
1435  
1436 96 $doc->_setDocumentElement($element);
1437 }
1438  
1439 sub toString {
1440 34 ▶ my $self = shift;
Subroutine toString: called CC=8 SCAR=21.5
1441 34 my $flag = shift;
1442  
1443 34 my $retval = "";
1444  
1445 34 ▶ if ( defined $XML::LibXML::skipXMLDeclaration
Branch: 1 branch
BranchTrueFalseTotal
if (defined $XML::LibXML::skipXMLDeclaration and $XML::LibXML::skipXMLDeclaration == 1) { } 4 30 34
Condition66%2/3
defined $XML::LibXML::skipXMLDeclaration and $XML::LibXML::skipXMLDeclaration == 1
!ll&&!rl&&r
0304
MC/DC50%1/2
defined $XML::LibXML::skipXMLDeclaration and $XML::LibXML::skipXMLDeclaration == 1
defined $XML::LibXML::skipXMLDeclaration $XML::LibXML::skipXMLDeclaration == 1
Truth table66%2/3
A and B
A= defined $XML::LibXML::skipXMLDeclarationB= $XML::LibXML::skipXMLDeclaration == 1
ABresult
0X0
100
111
1446 and $XML::LibXML::skipXMLDeclaration == 1 ) {
1447 4 foreach ( $self->childNodes ){
1448 4 ▶ next if $_->nodeType == XML::LibXML::XML_DTD_NODE()
Branch: 1 branch
BranchTrueFalseTotal
if $_->nodeType == 14 and $XML::LibXML::skipDTD 0 4 4
Condition33%1/3
$_->nodeType == 14 and $XML::LibXML::skipDTD
!ll&&!rl&&r
400
MC/DC0%0/2
$_->nodeType == 14 and $XML::LibXML::skipDTD
$_->nodeType == 14 $XML::LibXML::skipDTD
Truth table33%1/3
A and B
A= $_->nodeType == 14B= $XML::LibXML::skipDTD
ABresult
0X0
100
111
1449 and $XML::LibXML::skipDTD;
1450 4 $retval .= $_->toString;
1451 }
1452 }
1453 else {
1454 30 ▶ $flag ||= 0 unless defined $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag 28 2 30
Condition50%1/2
$flag ||= 0
l!l
028
MC/DC0%0/1
$flag ||= 0
$flag
Truth table50%1/2
A
A= $flag
Aresult
11
00
1455 30 $retval = $self->_toString($flag);
1456 }
1457  
1458 34 return $retval;
1459 }
1460  
1461 sub serialize {
1462 0 ▶ my $self = shift;
Subroutine serialize: not called CC=1 SCAR=6.9
1463 0 return $self->toString( @_ );
1464 }
1465  
1466 #-------------------------------------------------------------------------#
1467 # bad style xinclude processing #
1468 #-------------------------------------------------------------------------#
1469 sub process_xinclude {
1470 2 ▶ my $self = shift;
Subroutine process_xinclude: called CC=1 SCAR=0.0
1471 2 my $opts = shift;
1472 2 XML::LibXML->new->processXIncludes( $self, $opts );
1473 }
1474  
1475 sub insertProcessingInstruction {
1476 0 ▶ my $self = shift;
Subroutine insertProcessingInstruction: not called CC=2 SCAR=17.9
1477 0 my $target = shift;
1478 0 my $data = shift;
1479  
1480 0 my $pi = $self->createPI( $target, $data );
1481 0 my $root = $self->documentElement;
1482  
1483 0 ▶ if ( defined $root ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $root) { } 0 0 0
1484 # this is actually not correct, but i guess it's what the user
1485 # intends
1486 0 $self->insertBefore( $pi, $root );
1487 }
1488 else {
1489 # if no documentElement was found we just append the PI
1490 0 $self->appendChild( $pi );
1491 }
1492 }
1493  
1494 sub insertPI {
1495 0 ▶ my $self = shift;
Subroutine insertPI: not called CC=1 SCAR=6.9
1496 0 $self->insertProcessingInstruction( @_ );
1497 }
1498  
1499 #-------------------------------------------------------------------------#
1500 # DOM L3 Document functions.
1501 # added after robins implicit feature request
1502 #-------------------------------------------------------------------------#
1503 69 *getElementsByTagName = \&XML::LibXML::Element::getElementsByTagName;
1504 69 *getElementsByTagNameNS = \&XML::LibXML::Element::getElementsByTagNameNS;
1505 69 *getElementsByLocalName = \&XML::LibXML::Element::getElementsByLocalName;
1506  
1507 69 1;
1508  
1509 #-------------------------------------------------------------------------#
1510 # XML::LibXML::DocumentFragment Interface #
1511 #-------------------------------------------------------------------------#
1512 package XML::LibXML::DocumentFragment;
1513  
1514 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1515 69 @ISA = ('XML::LibXML::Node');
1516  
1517 sub toString {
1518 58 ▶ my $self = shift;
Subroutine toString: called CC=3 SCAR=11.0
1519 58 my $retval = "";
1520 58 ▶ if ( $self->hasChildNodes() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hasChildNodes) 58 0 58
1521 58 foreach my $n ( $self->childNodes() ) {
1522 104 $retval .= $n->toString(@_);
1523 }
1524 }
1525 58 return $retval;
1526 }
1527  
1528 69 *serialize = \&toString;
1529  
1530 69 1;
1531  
1532 #-------------------------------------------------------------------------#
1533 # XML::LibXML::Element Interface #
1534 #-------------------------------------------------------------------------#
1535 package XML::LibXML::Element;
1536  
1537 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1538 69 @ISA = ('XML::LibXML::Node');
1539 69 ▶use XML::LibXML qw(:ns :libxml);
Subroutine BEGIN: called CC=1 SCAR=0.0
1540 69 ▶use XML::LibXML::AttributeHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
1541 69 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
1542  
1543 69 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
1544  
1545 use overload
1546 69 '%{}' => 'getAttributeHash',
1547 'eq' => '_isSameNodeLax', '==' => '_isSameNodeLax',
1548 'ne' => '_isNotSameNodeLax', '!=' => '_isNotSameNodeLax',
1549 fallback => 1,
1550 69 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
1551  
1552 sub _isNotSameNodeLax {
1553 4 ▶ my ($self, $other) = @_;
Subroutine _isNotSameNodeLax: called CC=2 SCAR=7.2
1554  
1555 4 ▶ return ((not $self->_isSameNodeLax($other)) ? 1 : '');
Branch: 1 branch
BranchTrueFalseTotal
!$self->_isSameNodeLax($other) ? : 4 0 4
1556 }
1557  
1558 sub _isSameNodeLax {
1559 13 ▶ my ($self, $other) = @_;
Subroutine _isSameNodeLax: called CC=4 SCAR=13.9
1560  
1561 13 ▶ if (blessed($other) and $other->isa('XML::LibXML::Element'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->isa('XML::LibXML::Element')) { } 8 5 13
Condition66%2/3
builtin::blessed($other) and $other->isa("XML::LibXML::Element")
!ll&&!rl&&r
508
MC/DC50%1/2
builtin::blessed($other) and $other->isa("XML::LibXML::Element")
builtin::blessed($other) $other->isa("XML::LibXML::Element")
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa("XML::LibXML::Element")
ABresult
0X0
100
111
1562 {
1563 8 ▶ return ($self->isSameNode($other) ? 1 : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->isSameNode($other) ? : 4 4 8
1564 }
1565 else
1566 {
1567 5 return '';
1568 }
1569 }
1570  
1571 {
1572 69 my %tiecache;
1573  
1574 sub __destroy_tiecache
1575 {
1576 19194 ▶ delete $tiecache{ 0+$_[0] };
Subroutine __destroy_tiecache: called CC=1 SCAR=0.0
1577 }
1578  
1579 sub getAttributeHash
1580 {
1581 24 ▶ my $self = shift;
Subroutine getAttributeHash: called CC=2 SCAR=6.9
1582 24 ▶ if (!exists $tiecache{ 0+$self }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $tiecache{0 + $self}) 5 19 24
1583 5 tie my %attr, 'XML::LibXML::AttributeHash', $self, weaken => 1;
1584 5 $tiecache{ 0+$self } = \%attr;
1585 }
1586 24 return $tiecache{ 0+$self };
1587 }
1588 sub DESTROY
1589 {
1590 19194 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=1 SCAR=0.0
1591 19194 $self->__destroy_tiecache;
1592 19194 $self->SUPER::DESTROY;
1593 }
1594 }
1595  
1596 69 sub setNamespace {
1597 33 ▶ my $self = shift;
Subroutine setNamespace: called CC=4 SCAR=14.0
1598 33 my $n = $self->localname;
1599 33 ▶ if ( $self->_setNamespace(@_) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_setNamespace(@_)) 33 0 33
1600 33 ▶ if ( scalar @_ < 3 || $_[2] == 1 ){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ < 3 or $_[2] == 1) 5 28 33
Condition100%3/3
scalar @_ < 3 or $_[2] == 1
l!l&&r!l&&!r
3228
MC/DC100%2/2
scalar @_ < 3 or $_[2] == 1
scalar @_ < 3 $_[2] == 1
Truth table100%3/3
A or B
A= scalar @_ < 3B= $_[2] == 1
ABresult
1X1
011
000
1601 5 $self->setNodeName( $n );
1602 }
1603 33 return 1;
1604 }
1605 0 return 0;
1606 }
1607  
1608 sub getAttribute {
1609 67 ▶ my $self = shift;
Subroutine getAttribute: called CC=2 SCAR=6.9
1610 67 my $name = $_[0];
1611 67 ▶ if ( $name =~ /^xmlns(?::|$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^xmlns(?::|$)/) { } 21 46 67
1612 # user wants to get a namespace ...
1613 21 (my $prefix = $name )=~s/^xmlns:?//;
1614 21 $self->_getNamespaceDeclURI($prefix);
1615 }
1616 else {
1617 46 $self->_getAttribute(@_);
1618 }
1619 }
1620  
1621 sub setAttribute {
1622 38 ▶ my ( $self, $name, $value ) = @_;
Subroutine setAttribute: called CC=5 SCAR=16.1
1623 38 ▶ if ( $name =~ /^xmlns(?::|$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^xmlns(?::|$)/) { } 10 28 38
1624 # user wants to set the special attribute for declaring XML namespace ...
1625  
1626 # this is fine but not exactly DOM conformant behavior, btw (according to DOM we should
1627 # probably declare an attribute which looks like XML namespace declaration
1628 # but isn't)
1629 10 (my $nsprefix = $name )=~s/^xmlns:?//;
1630 10 my $nn = $self->nodeName;
1631 10 ▶ if ( $nn =~ /^\Q${nsprefix}\E:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nn =~ /^\Q$nsprefix\E:/) { } 1 9 10
1632 # the element has the same prefix
1633 1 ▶ $self->setNamespaceDeclURI($nsprefix,$value) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->setNamespaceDeclURI($nsprefix, $value) or $self->setNamespace($value, $nsprefix, 1) 1 0 1
1634 $self->setNamespace($value,$nsprefix,1);
1635 ##
1636 ## We set the namespace here.
1637 ## This is helpful, as in:
1638 ##
1639 ## | $e = XML::LibXML::Element->new('foo:bar');
1640 ## | $e->setAttribute('xmlns:foo','http://yoyodine')
1641 ##
1642 }
1643 else {
1644 # just modify the namespace
1645 9 ▶ $self->setNamespaceDeclURI($nsprefix, $value) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->setNamespaceDeclURI($nsprefix, $value) or $self->setNamespace($value, $nsprefix, 0) 7 2 9
1646 $self->setNamespace($value,$nsprefix,0);
1647 }
1648 }
1649 else {
1650 28 $self->_setAttribute($name, $value);
1651 }
1652 }
1653  
1654 sub getAttributeNS {
1655 23 ▶ my $self = shift;
Subroutine getAttributeNS: called CC=6 SCAR=18.6
1656 23 my ($nsURI, $name) = @_;
1657 23 ▶ croak("invalid attribute name") if !defined($name) or $name eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or $name eq "" 0 23 23
Condition33%1/3
not defined $name or $name eq ""
l!l&&r!l&&!r
0023
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name $name eq ""
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq ""
ABresult
1X1
011
000
1658 23 ▶ if ( defined($nsURI) and $nsURI eq XML_XMLNS_NS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nsURI and $nsURI eq 'http://www.w3.org/2000/xmlns/') { } 1 22 23
Condition100%3/3
defined $nsURI and $nsURI eq "http://www.w3.org/2000/xmlns/"
!ll&&!rl&&r
1211
MC/DC100%2/2
defined $nsURI and $nsURI eq "http://www.w3.org/2000/xmlns/"
defined $nsURI $nsURI eq "http://www.w3.org/2000/xmlns/"
Truth table100%3/3
A and B
A= defined $nsURIB= $nsURI eq "http://www.w3.org/2000/xmlns/"
ABresult
0X0
100
111
1659 1 ▶ $self->_getNamespaceDeclURI($name eq 'xmlns' ? undef : $name);
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'xmlns' ? : 1 0 1
1660 }
1661 else {
1662 22 $self->_getAttributeNS(@_);
1663 }
1664 }
1665  
1666 sub setAttributeNS {
1667 50 ▶ my ($self, $nsURI, $qname, $value)=@_;
Subroutine setAttributeNS: called CC=14 SCAR=29.5
1668 50 ▶ unless (defined $qname and length $qname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $qname and length $qname) 0 50 50
Condition33%1/3
defined $qname and length $qname
!ll&&!rl&&r
0050
MC/DC0%0/2
defined $qname and length $qname
defined $qname length $qname
Truth table33%1/3
A and B
A= defined $qnameB= length $qname
ABresult
0X0
100
111
1669 0 croak("bad name");
1670 }
1671 50 ▶ if (defined($nsURI) and $nsURI eq XML_XMLNS_NS) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nsURI and $nsURI eq "http://www.w3.org/2000/xmlns/") 1 49 50
Condition100%3/3
defined $nsURI and $nsURI eq "http://www.w3.org/2000/xmlns/"
!ll&&!rl&&r
5441
MC/DC100%2/2
defined $nsURI and $nsURI eq "http://www.w3.org/2000/xmlns/"
defined $nsURI $nsURI eq "http://www.w3.org/2000/xmlns/"
Truth table100%3/3
A and B
A= defined $nsURIB= $nsURI eq "http://www.w3.org/2000/xmlns/"
ABresult
0X0
100
111
1672 1 ▶ if ($qname !~ /^xmlns(?::|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($qname =~ /^xmlns(?::|$)/) 0 1 1
1673 0 croak("NAMESPACE ERROR: Namespace declarations must have the prefix 'xmlns'");
1674 }
1675 1 $self->setAttribute($qname,$value); # see implementation above
1676 1 return;
1677 }
1678 49 ▶ if ($qname=~/:/ and not (defined($nsURI) and length($nsURI))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qname =~ /:/ and not defined $nsURI && length $nsURI) 1 48 49
Condition83%5/6
$qname =~ /:/ and not defined $nsURI && length $nsURI
!ll&&!rl&&r
27211
defined $nsURI && length $nsURI
!ll&&!rl&&r
1021
MC/DC66%2/3
$qname =~ /:/ and not defined $nsURI && length $nsURI
$qname =~ /:/ defined $nsURI length $nsURI
Truth table75%3/4
A and not(B && C)
A= $qname =~ /:/B= defined $nsURIC= length $nsURI
ABCresult
0XX0
1110
10X1
1101
1679 1 croak("NAMESPACE ERROR: Attribute without a prefix cannot be in a namespace");
1680 }
1681 48 ▶ if ($qname=~/^xmlns(?:$|:)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qname =~ /^xmlns(?:$|:)/) 0 48 48
1682 0 croak("NAMESPACE ERROR: 'xmlns' prefix and qualified-name are reserved for the namespace ".XML_XMLNS_NS);
1683 }
1684 48 ▶ if ($qname=~/^xml:/ and not (defined $nsURI and $nsURI eq XML_XML_NS)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qname =~ /^xml:/ and not defined $nsURI && $nsURI eq "http://www.w3.org/XML/1998/namespace") 0 48 48
Condition50%3/6
$qname =~ /^xml:/ and not defined $nsURI && $nsURI eq "http://www.w3.org/XML/1998/namespace"
!ll&&!rl&&r
4710
defined $nsURI && $nsURI eq 'http://www.w3.org/XML/1998/namespace'
!ll&&!rl&&r
001
MC/DC0%0/3
$qname =~ /^xml:/ and not defined $nsURI && $nsURI eq "http://www.w3.org/XML/1998/namespace"
$qname =~ /^xml:/ defined $nsURI $nsURI eq 'http://www.w3.org/XML/1998/namespace'
Truth table50%2/4
A and not(B && C)
A= $qname =~ /^xml:/B= defined $nsURIC= $nsURI eq 'http://www.w3.org/XML/1998/namespace'
ABCresult
0XX0
1110
10X1
1101
1685 0 croak("NAMESPACE ERROR: 'xml' prefix is reserved for the namespace ".XML_XML_NS);
1686 }
1687 48 ▶ $self->_setAttributeNS( defined $nsURI ? $nsURI : undef, $qname, $value );
Branch: 1 branch
BranchTrueFalseTotal
defined $nsURI ? : 44 4 48
1688 }
1689  
1690 sub getElementsByTagName {
1691 12 ▶ my ( $node , $name ) = @_;
Subroutine getElementsByTagName: called CC=3 SCAR=11.0
1692 12 ▶ my $xpath = $name eq '*' ? "descendant::*" : "descendant::*[name()='$name']";
Branch: 1 branch
BranchTrueFalseTotal
$name eq '*' ? : 1 11 12
1693 12 my @nodes = $node->_findnodes($xpath);
1694 12 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
1695 }
1696  
1697 sub getElementsByTagNameNS {
1698 13 ▶ my ( $node, $nsURI, $name ) = @_;
Subroutine getElementsByTagNameNS: called CC=5 SCAR=16.1
1699 13 my $xpath;
1700 13 ▶ if ( $name eq '*' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq '*') { } 6 7 13
elsif ($nsURI eq '*') { } 5 2 7
1701 6 ▶ if ( $nsURI eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nsURI eq '*') { } 3 3 6
1702 3 $xpath = "descendant::*";
1703 } else {
1704 3 $xpath = "descendant::*[namespace-uri()='$nsURI']";
1705 }
1706 } elsif ( $nsURI eq '*' ) {
1707 5 $xpath = "descendant::*[local-name()='$name']";
1708 } else {
1709 2 $xpath = "descendant::*[local-name()='$name' and namespace-uri()='$nsURI']";
1710 }
1711 13 my @nodes = $node->_findnodes($xpath);
1712 13 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 13 0 13
1713 }
1714  
1715 sub getElementsByLocalName {
1716 4 ▶ my ( $node,$name ) = @_;
Subroutine getElementsByLocalName: called CC=3 SCAR=11.0
1717 4 my $xpath;
1718 4 ▶ if ($name eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq '*') { } 1 3 4
1719 1 $xpath = "descendant::*";
1720 } else {
1721 3 $xpath = "descendant::*[local-name()='$name']";
1722 }
1723 4 my @nodes = $node->_findnodes($xpath);
1724 4 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
1725 }
1726  
1727 sub getChildrenByTagName {
1728 12 ▶ my ( $node, $name ) = @_;
Subroutine getChildrenByTagName: called CC=3 SCAR=11.0
1729 12 my @nodes;
1730 12 ▶ if ($name eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq '*') { } 3 9 12
1731 3 @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() }
1732 $node->childNodes();
1733 } else {
1734 9 @nodes = grep { $_->nodeName eq $name } $node->childNodes();
1735 }
1736 12 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
1737 }
1738  
1739 sub getChildrenByLocalName {
1740 3 ▶ my ( $node, $name ) = @_;
Subroutine getChildrenByLocalName: called CC=2 SCAR=7.1
1741 # my @nodes;
1742 # if ($name eq '*') {
1743 # @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() }
1744 # $node->childNodes();
1745 # } else {
1746 # @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() and
1747 # $_->localName eq $name } $node->childNodes();
1748 # }
1749 # return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
1750 3 my @nodes = $node->_getChildrenByTagNameNS('*',$name);
1751 3 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
1752 }
1753  
1754 sub getChildrenByTagNameNS {
1755 9 ▶ my ( $node, $nsURI, $name ) = @_;
Subroutine getChildrenByTagNameNS: called CC=2 SCAR=7.1
1756 9 my @nodes = $node->_getChildrenByTagNameNS($nsURI,$name);
1757 9 ▶ return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 0 9
1758 }
1759  
1760 sub appendWellBalancedChunk {
1761 1 ▶ my ( $self, $chunk ) = @_;
Subroutine appendWellBalancedChunk: called CC=1 SCAR=0.0
1762  
1763 1 my $local_parser = XML::LibXML->new();
1764 1 my $frag = $local_parser->parse_xml_chunk( $chunk );
1765  
1766 1 $self->appendChild( $frag );
1767 }
1768  
1769 69 1;
1770  
1771 #-------------------------------------------------------------------------#
1772 # XML::LibXML::Text Interface #
1773 #-------------------------------------------------------------------------#
1774 package XML::LibXML::Text;
1775  
1776 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1777 69 @ISA = ('XML::LibXML::Node');
1778  
1779 1 ▶sub attributes { return; }
Subroutine attributes: called CC=1 SCAR=0.0
1780  
1781 sub deleteDataString {
1782 5 ▶ my ($node, $string, $all) = @_;
Subroutine deleteDataString: called CC=1 SCAR=0.0
1783  
1784 5 return $node->replaceDataString($string, '', $all);
1785 }
1786  
1787 sub replaceDataString {
1788 9 ▶ my ( $node, $left_proto, $right,$all ) = @_;
Subroutine replaceDataString: called CC=2 SCAR=6.9
1789  
1790 # Assure we exchange the strings and not expressions!
1791 9 my $left = quotemeta($left_proto);
1792  
1793 9 my $datastr = $node->nodeValue();
1794 9 ▶ if ( $all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) { } 3 6 9
1795 3 $datastr =~ s/$left/$right/g;
1796 }
1797 else{
1798 6 $datastr =~ s/$left/$right/;
1799 }
1800 9 $node->setData( $datastr );
1801 }
1802  
1803 sub replaceDataRegEx {
1804 6 ▶ my ( $node, $leftre, $rightre, $flags ) = @_;
Subroutine replaceDataRegEx: called CC=4 SCAR=14.0
1805 6 ▶ return unless defined $leftre;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $leftre 0 6 6
1806 6 ▶ $rightre ||= "";
Condition50%1/2
$rightre ||= ""
l!l
60
MC/DC0%0/1
$rightre ||= ""
$rightre
Truth table50%1/2
A
A= $rightre
Aresult
11
00
1807  
1808 6 my $datastr = $node->nodeValue();
1809 6 my $restr = "s/" . $leftre . "/" . $rightre . "/";
1810 6 ▶ $restr .= $flags if defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flags 2 4 6
1811  
1812 6 eval '$datastr =~ '. $restr;
1813  
1814 6 $node->setData( $datastr );
1815 }
1816  
1817 69 1;
1818  
1819 package XML::LibXML::Comment;
1820  
1821 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1822 69 @ISA = ('XML::LibXML::Text');
1823  
1824 69 1;
1825  
1826 package XML::LibXML::CDATASection;
1827  
1828 69 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1829 69 @ISA = ('XML::LibXML::Text');
1830  
1831 69 1;
1832  
1833 #-------------------------------------------------------------------------#
1834 # XML::LibXML::Attribute Interface #
1835 #-------------------------------------------------------------------------#
1836 package XML::LibXML::Attr;
1837 69 ▶use vars qw( @ISA ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
1838 69 @ISA = ('XML::LibXML::Node') ;
1839  
1840 sub setNamespace {
1841 2 ▶ my ($self,$href,$prefix) = @_;
Subroutine setNamespace: called CC=2 SCAR=7.2
1842 2 my $n = $self->localname;
1843 2 ▶ if ( $self->_setNamespace($href,$prefix) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_setNamespace($href, $prefix)) 2 0 2
1844 2 $self->setNodeName($n);
1845 2 return 1;
1846 }
1847  
1848 0 return 0;
1849 }
1850  
1851 69 1;
1852  
1853 #-------------------------------------------------------------------------#
1854 # XML::LibXML::Dtd Interface #
1855 #-------------------------------------------------------------------------#
1856 # this is still under construction
1857 #
1858 package XML::LibXML::Dtd;
1859 69 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1860 69 @ISA = ('XML::LibXML::Node');
1861  
1862 # at least DESTROY and CLONE_SKIP must be inherited
1863  
1864 69 1;
1865  
1866 #-------------------------------------------------------------------------#
1867 # XML::LibXML::PI Interface #
1868 #-------------------------------------------------------------------------#
1869 package XML::LibXML::PI;
1870 69 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1871 69 @ISA = ('XML::LibXML::Node');
1872  
1873 sub setData {
1874 3 ▶ my $pi = shift;
Subroutine setData: called CC=3 SCAR=11.0
1875  
1876 3 my $string = "";
1877 3 ▶ if ( scalar @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 1 3
1878 2 $string = shift;
1879 }
1880 else {
1881 1 my %h = @_;
1882 1 $string = join " ", map {$_.'="'.$h{$_}.'"'} keys %h;
1883 }
1884  
1885 # the spec says any char but "?>" [17]
1886 3 ▶ $pi->_setData( $string ) unless $string =~ /\?>/;
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /\?>/ 3 0 3
1887 }
1888  
1889 69 1;
1890  
1891 #-------------------------------------------------------------------------#
1892 # XML::LibXML::Namespace Interface #
1893 #-------------------------------------------------------------------------#
1894 package XML::LibXML::Namespace;
1895  
1896 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
1897  
1898 # In fact, this is not a node!
1899 0 ▶sub prefix { return "xmlns"; }
Subroutine prefix: not called CC=1 SCAR=6.9
1900 0 ▶sub getPrefix { return "xmlns"; }
Subroutine getPrefix: not called CC=1 SCAR=6.9
1901 0 ▶sub getNamespaceURI { return "http://www.w3.org/2000/xmlns/" };
Subroutine getNamespaceURI: not called CC=1 SCAR=6.9
1902  
1903 0 ▶sub getNamespaces { return (); }
Subroutine getNamespaces: not called CC=1 SCAR=6.9
1904  
1905 sub nodeName {
1906 4 ▶ my $self = shift;
Subroutine nodeName: called CC=3 SCAR=11.0
1907 4 my $nsP = $self->localname;
1908 4 ▶ return ( defined($nsP) && length($nsP) ) ? "xmlns:$nsP" : "xmlns";
Branch: 1 branch
BranchTrueFalseTotal
defined $nsP && length $nsP ? : 2 2 4
Condition66%2/3
defined $nsP and length $nsP
!ll&&!rl&&r
202
MC/DC50%1/2
defined $nsP and length $nsP
defined $nsP length $nsP
Truth table66%2/3
A and B
A= defined $nsPB= length $nsP
ABresult
0X0
100
111
1909 }
1910 4 ▶sub name { goto &nodeName }
Subroutine name: called CC=1 SCAR=0.0
1911 0 ▶sub getName { goto &nodeName }
Subroutine getName: not called CC=1 SCAR=6.9
1912  
1913 sub isEqualNode {
1914 0 ▶ my ( $self, $ref ) = @_;
Subroutine isEqualNode: not called CC=2 SCAR=17.9
1915 0 ▶ if ( ref($ref) eq "XML::LibXML::Namespace" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref eq "XML::LibXML::Namespace") 0 0 0
1916 0 return $self->_isEqual($ref);
1917 }
1918 0 return 0;
1919 }
1920  
1921 sub isSameNode {
1922 0 ▶ my ( $self, $ref ) = @_;
Subroutine isSameNode: not called CC=2 SCAR=17.9
1923 0 ▶ if ( $$self == $$ref ){
Branch: 1 branch
BranchTrueFalseTotal
if ($$self == $$ref) 0 0 0
1924 0 return 1;
1925 }
1926 0 return 0;
1927 }
1928  
1929 69 1;
1930  
1931 #-------------------------------------------------------------------------#
1932 # XML::LibXML::NamedNodeMap Interface #
1933 #-------------------------------------------------------------------------#
1934 package XML::LibXML::NamedNodeMap;
1935  
1936 69 ▶use XML::LibXML qw(:libxml);
Subroutine BEGIN: called CC=1 SCAR=0.0
1937  
1938 sub CLONE_SKIP {
1939 0 ▶ return $XML::LibXML::__threads_shared ? 0 : 1;
Subroutine CLONE_SKIP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
1940 }
1941  
1942 sub new {
1943 2 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
1944 2 my $self = bless { Nodes => [@_] }, $class;
1945 2 $self->{NodeMap} = { map { $_->nodeName => $_ } @_ };
1946 2 return $self;
1947 }
1948  
1949 2 ▶sub length { return scalar( @{$_[0]->{Nodes}} ); }
Subroutine length: called CC=1 SCAR=0.0
1950 0 ▶sub nodes { return $_[0]->{Nodes}; }
Subroutine nodes: not called CC=1 SCAR=6.9
1951 0 ▶sub item { $_[0]->{Nodes}->[$_[1]]; }
Subroutine item: not called CC=1 SCAR=6.9
1952  
1953 sub getNamedItem {
1954 1 ▶ my $self = shift;
Subroutine getNamedItem: called CC=1 SCAR=0.0
1955 1 my $name = shift;
1956  
1957 1 return $self->{NodeMap}->{$name};
1958 }
1959  
1960 sub setNamedItem {
1961 3 ▶ my $self = shift;
Subroutine setNamedItem: called CC=6 SCAR=18.7
1962 3 my $node = shift;
1963  
1964 3 my $retval;
1965 3 ▶ if ( defined $node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 3 0 3
1966 3 ▶ if ( scalar @{$self->{Nodes}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'Nodes'};}) { } 3 0 3
1967 3 my $name = $node->nodeName();
1968 3 ▶ if ( $node->nodeType() == XML_NAMESPACE_DECL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->nodeType == 18) 0 3 3
1969 0 return;
1970 }
1971 3 ▶ if ( defined $self->{NodeMap}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'NodeMap'}{$name}) { } 1 2 3
1972 1 ▶ if ( $node->isSameNode( $self->{NodeMap}->{$name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isSameNode($self->{"NodeMap"}{$name})) 0 1 1
1973 0 return;
1974 }
1975 1 $retval = $self->{NodeMap}->{$name}->replaceNode( $node );
1976 }
1977 else {
1978 2 $self->{Nodes}->[0]->addSibling($node);
1979 }
1980  
1981 3 $self->{NodeMap}->{$name} = $node;
1982 3 push @{$self->{Nodes}}, $node;
1983 }
1984 else {
1985 # not done yet
1986 # can this be properly be done???
1987 0 warn "not done yet\n";
1988 }
1989 }
1990 3 return $retval;
1991 }
1992  
1993 sub removeNamedItem {
1994 1 ▶ my $self = shift;
Subroutine removeNamedItem: called CC=3 SCAR=11.2
1995 1 my $name = shift;
1996 1 my $retval;
1997 1 ▶ if ( $name =~ /^xmlns/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^xmlns/) { } 0 1 1
elsif (exists $self->{'NodeMap'}{$name}) { } 1 0 1
1998 0 warn "not done yet\n";
1999 }
2000 elsif ( exists $self->{NodeMap}->{$name} ) {
2001 1 $retval = $self->{NodeMap}->{$name};
2002 1 $retval->unbindNode;
2003 1 delete $self->{NodeMap}->{$name};
2004 1 $self->{Nodes} = [grep {not($retval->isSameNode($_))} @{$self->{Nodes}}];
2005 }
2006  
2007 1 return $retval;
2008 }
2009  
2010 sub getNamedItemNS {
2011 0 ▶ my $self = shift;
Subroutine getNamedItemNS: not called CC=1 SCAR=6.9
2012 0 my $nsURI = shift;
2013 0 my $name = shift;
2014 0 return undef;
2015 }
2016  
2017 sub setNamedItemNS {
2018 0 ▶ my $self = shift;
Subroutine setNamedItemNS: not called CC=1 SCAR=6.9
2019 0 my $nsURI = shift;
2020 0 my $node = shift;
2021 0 return undef;
2022 }
2023  
2024 sub removeNamedItemNS {
2025 0 ▶ my $self = shift;
Subroutine removeNamedItemNS: not called CC=1 SCAR=6.9
2026 0 my $nsURI = shift;
2027 0 my $name = shift;
2028 0 return undef;
2029 }
2030  
2031 69 1;
2032  
2033 package XML::LibXML::_SAXParser;
2034  
2035 # this is pseudo class!!! and it will be removed as soon all functions
2036 # moved to XS level
2037  
2038 69 ▶use XML::SAX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
2039  
2040 sub CLONE_SKIP {
2041 0 ▶ return $XML::LibXML::__threads_shared ? 0 : 1;
Subroutine CLONE_SKIP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
2042 }
2043  
2044 # these functions will use SAX exceptions as soon i know how things really work
2045 sub warning {
2046 0 ▶ my ( $parser, $message, $line, $col ) = @_;
Subroutine warning: not called CC=1 SCAR=6.9
2047 0 my $error = XML::SAX::Exception::Parse->new( LineNumber => $line,
2048 ColumnNumber => $col,
2049 Message => $message, );
2050 0 $parser->{HANDLER}->warning( $error );
2051 }
2052  
2053 sub error {
2054 0 ▶ my ( $parser, $message, $line, $col ) = @_;
Subroutine error: not called CC=1 SCAR=6.9
2055  
2056 0 my $error = XML::SAX::Exception::Parse->new( LineNumber => $line,
2057 ColumnNumber => $col,
2058 Message => $message, );
2059 0 $parser->{HANDLER}->error( $error );
2060 }
2061  
2062 sub fatal_error {
2063 1 ▶ my ( $parser, $message, $line, $col ) = @_;
Subroutine fatal_error: called CC=1 SCAR=0.0
2064 1 my $error = XML::SAX::Exception::Parse->new( LineNumber => $line,
2065 ColumnNumber => $col,
2066 Message => $message, );
2067 1 $parser->{HANDLER}->fatal_error( $error );
2068 }
2069  
2070 69 1;
2071  
2072 package XML::LibXML::RelaxNG;
2073  
2074 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
2075  
2076 sub new {
2077 11 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=13.9
2078 11 my %args = @_;
2079  
2080 11 my $self = undef;
2081 11 ▶ if ( defined $args{location} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $args{'location'}) { } 6 5 11
elsif (defined $args{'string'}) { } 3 2 5
elsif (defined $args{'DOM'}) { } 2 0 2
2082 6 $self = $class->parse_location( $args{location}, XML::LibXML->_parser_options(\%args), $args{recover} );
2083 }
2084 elsif ( defined $args{string} ) {
2085 3 $self = $class->parse_buffer( $args{string}, XML::LibXML->_parser_options(\%args), $args{recover} );
2086 }
2087 elsif ( defined $args{DOM} ) {
2088 2 $self = $class->parse_document( $args{DOM}, XML::LibXML->_parser_options(\%args), $args{recover} );
2089 }
2090  
2091 6 return $self;
2092 }
2093  
2094 69 1;
2095  
2096 package XML::LibXML::Schema;
2097  
2098 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
2099  
2100 sub new {
2101 9 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
2102 9 my %args = @_;
2103  
2104 9 my $self = undef;
2105 9 ▶ if ( defined $args{location} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'location'}) { } 5 4 9
elsif (defined $args{'string'}) { } 4 0 4
2106 5 $self = $class->parse_location( $args{location}, XML::LibXML->_parser_options(\%args), $args{recover} );
2107 }
2108 elsif ( defined $args{string} ) {
2109 4 $self = $class->parse_buffer( $args{string}, XML::LibXML->_parser_options(\%args), $args{recover} );
2110 }
2111  
2112 5 return $self;
2113 }
2114  
2115 69 1;
2116  
2117 #-------------------------------------------------------------------------#
2118 # XML::LibXML::Pattern Interface #
2119 #-------------------------------------------------------------------------#
2120  
2121 package XML::LibXML::Pattern;
2122  
2123 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
2124  
2125 sub new {
2126 1 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.8
2127 1 my ($pattern,$ns_map)=@_;
2128 1 my $self = undef;
2129  
2130 1 ▶ unless (UNIVERSAL::can($class,'_compilePattern')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($class, "_compilePattern")) 0 1 1
2131 0 croak("Cannot create XML::LibXML::Pattern - ".
2132 "your libxml2 is compiled without pattern support!");
2133 }
2134  
2135 1 ▶ if (ref($ns_map) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns_map eq 'HASH') { } 1 0 1
2136 # translate prefix=>URL hash to a (URL,prefix) list
2137 1 $self = $class->_compilePattern($pattern,0,[reverse %$ns_map]);
2138 } else {
2139 0 $self = $class->_compilePattern($pattern,0);
2140 }
2141 1 return $self;
2142 }
2143  
2144 69 1;
2145  
2146 #-------------------------------------------------------------------------#
2147 # XML::LibXML::RegExp Interface #
2148 #-------------------------------------------------------------------------#
2149  
2150 package XML::LibXML::RegExp;
2151  
2152 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
2153  
2154 sub new {
2155 3 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.4
2156 3 my ($regexp)=@_;
2157 3 ▶ unless (UNIVERSAL::can($class,'_compile')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($class, "_compile")) 0 3 3
2158 0 croak("Cannot create XML::LibXML::RegExp - ".
2159 "your libxml2 is compiled without regexp support!");
2160 }
2161 3 return $class->_compile($regexp);
2162 }
2163  
2164 69 1;
2165  
2166 #-------------------------------------------------------------------------#
2167 # XML::LibXML::XPathExpression Interface #
2168 #-------------------------------------------------------------------------#
2169  
2170 package XML::LibXML::XPathExpression;
2171  
2172 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
2173  
2174 69 1;
2175  
2176  
2177 #-------------------------------------------------------------------------#
2178 # XML::LibXML::InputCallback Interface #
2179 #-------------------------------------------------------------------------#
2180 package XML::LibXML::InputCallback;
2181  
2182 69 ▶use vars qw($_CUR_CB @_GLOBAL_CALLBACKS @_CB_STACK $_CB_NESTED_DEPTH @_CB_NESTED_STACK);
Subroutine BEGIN: called CC=1 SCAR=0.0
2183  
2184 BEGIN {
2185 69 ▶ $_CUR_CB = undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
2186 69 @_GLOBAL_CALLBACKS = ();
2187 69 @_CB_STACK = ();
2188 69 $_CB_NESTED_DEPTH = 0;
2189 69 @_CB_NESTED_STACK = ();
2190 }
2191  
2192 sub CLONE_SKIP {
2193 0 ▶ return $XML::LibXML::__threads_shared ? 0 : 1;
Subroutine CLONE_SKIP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::__threads_shared ? : 0 0 0
2194 }
2195  
2196 #-------------------------------------------------------------------------#
2197 # global callbacks #
2198 #-------------------------------------------------------------------------#
2199 sub _callback_match {
2200 116 ▶ my $uri = shift;
Subroutine _callback_match: called CC=4 SCAR=13.9
2201 116 my $retval = 0;
2202  
2203 # loop through the callbacks, and find the first matching one.
2204 # The callbacks are stored in execution order (reverse stack order).
2205 # Any new global callbacks are shifted to the callback stack.
2206 116 foreach my $cb ( @_GLOBAL_CALLBACKS ) {
2207  
2208 # callbacks have to return 1, 0 or undef, while 0 and undef
2209 # are handled the same way.
2210 # in fact, if callbacks return other values, the global match
2211 # assumes silently that the callback failed.
2212  
2213 37 $retval = $cb->[0]->($uri);
2214  
2215 37 ▶ if ( defined $retval and $retval == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $retval and $retval == 1) 25 12 37
Condition100%3/3
defined $retval and $retval == 1
!ll&&!rl&&r
3925
MC/DC100%2/2
defined $retval and $retval == 1
defined $retval $retval == 1
Truth table100%3/3
A and B
A= defined $retvalB= $retval == 1
ABresult
0X0
100
111
2216 # make the other callbacks use this callback
2217 25 $_CUR_CB = $cb;
2218 25 unshift @_CB_STACK, $cb;
2219 25 last;
2220 }
2221 }
2222  
2223 116 return $retval;
2224 }
2225  
2226 sub _callback_open {
2227 25 ▶ my $uri = shift;
Subroutine _callback_open: called CC=4 SCAR=16.1
2228 25 my $retval = undef;
2229  
2230 # the open callback has to return a defined value.
2231 # if one works on files this can be a file handle. But
2232 # depending on the needs of the callback it also can be a
2233 # database handle or a integer labeling a certain dataset.
2234  
2235 25 ▶ if ( defined $_CUR_CB ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $XML::LibXML::InputCallback::_CUR_CB) 25 0 25
2236 25 $retval = $_CUR_CB->[1]->( $uri );
2237  
2238 # reset the callbacks, if one callback cannot open an uri
2239 25 ▶ if ( not defined $retval or $retval == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $retval or $retval == 0) 0 25 25
Condition33%1/3
not defined $retval or $retval == 0
l!l&&r!l&&!r
0025
MC/DC0%0/2
not defined $retval or $retval == 0
not defined $retval $retval == 0
Truth table33%1/3
not(A) or B
A= not defined $retvalB= $retval == 0
ABresult
1X1
011
000
2240 0 shift @_CB_STACK;
2241 0 $_CUR_CB = $_CB_STACK[0];
2242 }
2243 }
2244  
2245 25 return $retval;
2246 }
2247  
2248 sub _callback_read {
2249 74 ▶ my $fh = shift;
Subroutine _callback_read: called CC=2 SCAR=7.0
2250 74 my $buflen = shift;
2251  
2252 74 my $retval = undef;
2253  
2254 74 ▶ if ( defined $_CUR_CB ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $XML::LibXML::InputCallback::_CUR_CB) 74 0 74
2255 74 $retval = $_CUR_CB->[2]->( $fh, $buflen );
2256 }
2257  
2258 74 return $retval;
2259 }
2260  
2261 sub _callback_close {
2262 25 ▶ my $fh = shift;
Subroutine _callback_close: called CC=2 SCAR=7.0
2263 25 my $retval = 0;
2264  
2265 25 ▶ if ( defined $_CUR_CB ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $XML::LibXML::InputCallback::_CUR_CB) 25 0 25
2266 25 $retval = $_CUR_CB->[3]->( $fh );
2267 25 shift @_CB_STACK;
2268 25 $_CUR_CB = $_CB_STACK[0];
2269 }
2270  
2271 25 return $retval;
2272 }
2273  
2274 #-------------------------------------------------------------------------#
2275 # member functions and methods #
2276 #-------------------------------------------------------------------------#
2277  
2278 sub new {
2279 168 ▶ my $CLASS = shift;
Subroutine new: called CC=1 SCAR=0.0
2280 168 return bless {'_CALLBACKS' => []}, $CLASS;
2281 }
2282  
2283 # add a callback set to the callback stack
2284 # synopsis: $icb->register_callbacks( [$match_cb, $open_cb, $read_cb, $close_cb] );
2285 sub register_callbacks {
2286 11 ▶ my $self = shift;
Subroutine register_callbacks: called CC=3 SCAR=11.8
2287 11 my $cbset = shift;
2288  
2289 # test if callback set is complete
2290 11 ▶ if ( ref $cbset eq "ARRAY" and scalar( @$cbset ) == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cbset eq "ARRAY" and scalar @$cbset == 4) 11 0 11
Condition33%1/3
ref $cbset eq "ARRAY" and scalar @$cbset == 4
!ll&&!rl&&r
0011
MC/DC0%0/2
ref $cbset eq "ARRAY" and scalar @$cbset == 4
ref $cbset eq "ARRAY" scalar @$cbset == 4
Truth table33%1/3
A and B
A= ref $cbset eq "ARRAY"B= scalar @$cbset == 4
ABresult
0X0
100
111
2291 11 unshift @{$self->{_CALLBACKS}}, $cbset;
2292 }
2293 }
2294  
2295 # remove a callback set to the callback stack
2296 # if a callback set is passed, this function will check for the match function
2297 sub unregister_callbacks {
2298 1 ▶ my $self = shift;
Subroutine unregister_callbacks: called CC=3 SCAR=12.6
2299 1 my $cbset = shift;
2300 1 ▶ if ( ref $cbset eq "ARRAY" and scalar( @$cbset ) == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cbset eq 'ARRAY' and scalar @$cbset == 4) { } 1 0 1
Condition33%1/3
ref $cbset eq "ARRAY" and scalar @$cbset == 4
!ll&&!rl&&r
001
MC/DC0%0/2
ref $cbset eq "ARRAY" and scalar @$cbset == 4
ref $cbset eq "ARRAY" scalar @$cbset == 4
Truth table33%1/3
A and B
A= ref $cbset eq "ARRAY"B= scalar @$cbset == 4
ABresult
0X0
100
111
2301 1 $self->{_CALLBACKS} = [grep { $_->[0] != $cbset->[0] } @{$self->{_CALLBACKS}}];
2302 }
2303 else {
2304 0 shift @{$self->{_CALLBACKS}};
2305 }
2306 }
2307  
2308 # make libxml2 use the callbacks
2309 sub init_callbacks {
2310 684 ▶ my $self = shift;
Subroutine init_callbacks: called CC=11 SCAR=24.4
2311 684 my $parser = shift;
2312  
2313 #initialize the libxml2 callbacks unless this is a nested callback
2314 684 ▶ $self->lib_init_callbacks() unless($_CB_NESTED_DEPTH);
Branch: 1 branch
BranchTrueFalseTotal
unless $XML::LibXML::InputCallback::_CB_NESTED_DEPTH 677 7 684
2315  
2316 #store the callbacks for any outer executing parser instance
2317 684 $_CB_NESTED_DEPTH++;
2318 684 push @_CB_NESTED_STACK, [
2319 $_CUR_CB,
2320 [@_CB_STACK],
2321 [@_GLOBAL_CALLBACKS],
2322 ];
2323  
2324 #initialize the callback variables for the current parser
2325 684 $_CUR_CB = undef;
2326 684 @_CB_STACK = ();
2327 684 @_GLOBAL_CALLBACKS = @{ $self->{_CALLBACKS} };
2328  
2329 #attach parser specific callbacks
2330 684 ▶ if($parser) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser) 684 0 684
2331 684 my $mcb = $parser->match_callback();
2332 684 my $ocb = $parser->open_callback();
2333 684 my $rcb = $parser->read_callback();
2334 684 my $ccb = $parser->close_callback();
2335 684 ▶ if ( defined $mcb and defined $ocb and defined $rcb and defined $ccb ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mcb and defined $ocb and defined $rcb and defined $ccb) 4 680 684
Condition66%6/9
defined $mcb and defined $ocb and defined $rcb and defined $ccb
!ll&&!rl&&r
68004
defined $mcb and defined $ocb and defined $rcb
!ll&&!rl&&r
68004
defined $mcb and defined $ocb
!ll&&!rl&&r
68004
MC/DC25%1/4
defined $mcb and defined $ocb and defined $rcb and defined $ccb
defined $mcb defined $ocb defined $rcb defined $ccb
Truth table40%2/5
A and B and C and D
A= defined $mcbB= defined $ocbC= defined $rcbD= defined $ccb
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2336 4 unshift @_GLOBAL_CALLBACKS, [$mcb, $ocb, $rcb, $ccb];
2337 }
2338 }
2339  
2340 #attach global callbacks
2341 684 ▶ if ( defined $XML::LibXML::match_cb and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $XML::LibXML::match_cb and defined $XML::LibXML::open_cb and defined $XML::LibXML::read_cb and defined $XML::LibXML::close_cb) 1 683 684
Condition66%6/9
defined $XML::LibXML::match_cb and defined $XML::LibXML::open_cb and defined $XML::LibXML::read_cb and defined $XML::LibXML::close_cb
!ll&&!rl&&r
68301
defined $XML::LibXML::match_cb and defined $XML::LibXML::open_cb and defined $XML::LibXML::read_cb
!ll&&!rl&&r
68301
defined $XML::LibXML::match_cb and defined $XML::LibXML::open_cb
!ll&&!rl&&r
68301
MC/DC25%1/4
defined $XML::LibXML::match_cb and defined $XML::LibXML::open_cb and defined $XML::LibXML::read_cb and defined $XML::LibXML::close_cb
defined $XML::LibXML::match_cb defined $XML::LibXML::open_cb defined $XML::LibXML::read_cb defined $XML::LibXML::close_cb
Truth table40%2/5
A and B and C and D
A= defined $XML::LibXML::match_cbB= defined $XML::LibXML::open_cbC= defined $XML::LibXML::read_cbD= defined $XML::LibXML::close_cb
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2342 defined $XML::LibXML::open_cb and
2343 defined $XML::LibXML::read_cb and
2344 defined $XML::LibXML::close_cb ) {
2345 1 push @_GLOBAL_CALLBACKS, [$XML::LibXML::match_cb,
2346 $XML::LibXML::open_cb,
2347 $XML::LibXML::read_cb,
2348 $XML::LibXML::close_cb];
2349 }
2350 }
2351  
2352 # reset libxml2's callbacks
2353 sub cleanup_callbacks {
2354 684 ▶ my $self = shift;
Subroutine cleanup_callbacks: called CC=2 SCAR=6.9
2355  
2356 #restore the callbacks for the outer parser instance
2357 684 $_CB_NESTED_DEPTH--;
2358 684 my $saved = pop @_CB_NESTED_STACK;
2359 684 $_CUR_CB = $saved->[0];
2360 684 @_CB_STACK = (@{$saved->[1]});
2361 684 @_GLOBAL_CALLBACKS = (@{$saved->[2]});
2362  
2363 #clean up the libxml2 callbacks unless there are still outer parsing instances
2364 684 ▶ $self->lib_cleanup_callbacks() unless($_CB_NESTED_DEPTH);
Branch: 1 branch
BranchTrueFalseTotal
unless $XML::LibXML::InputCallback::_CB_NESTED_DEPTH 677 7 684
2365 }
2366  
2367 69 $XML::LibXML::__loaded=1;
2368  
2369 69 1;
2370  
2371 __END__
« blib/lib/XML/LibXML/Reader.pm ↑ Summary blib/lib/XML/LibXML/Error.pm »