blib/lib/XML/LibXML/SAX.pm

filter: Statementstmt 82.6% 62 / 75 Branchbran 55.5% 10 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 82.3% 14 / 17 Podpod 50.0% 1 / 2 totaltotal 77.6% 87 / 112 CC 10 SCAR 9.6
CC
10
Cov
77%
CLONE_SKIP
6.0
_parse_bytestream
6.0
_parse
4.1
CRAP 2.6
« blib/lib/XML/LibXML/NodeList.pm ↑ Summary blib/lib/XML/LibXML/Number.pm »
1 # $Id$
2 #
3 # This is free software, you may use it and distribute it under the same terms as
4 # Perl itself.
5 #
6 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7 #
8 #
9  
10 package XML::LibXML::SAX;
11  
12 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 $VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE
18  
19 3 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use XML::SAX::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use parent qw(XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub CLONE_SKIP {
28 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
29 }
30  
31 sub set_feature {
32 8 ▶ my ($self, $feat, $val) = @_;
Subroutine set_feature: called CC=2 SCAR=7.9
Pod documented
33  
34 8 ▶ if ($feat eq 'http://xmlns.perl.org/sax/join-character-data') {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat eq "http://xmlns.perl.org/sax/join-character-data") 0 8 8
35 0 $self->{JOIN_CHARACTERS} = $val;
36 0 return 1;
37 }
38  
39 8 shift(@_);
40 8 return $self->SUPER::set_feature(@_);
41 }
42  
43 sub _parse_characterstream {
44 0 ▶ my ( $self, $fh ) = @_;
Subroutine _parse_characterstream: not called CC=1 SCAR=6.9
45 # this my catch the xml decl, so the parser won't get confused about
46 # a possibly wrong encoding.
47 0 croak( "not implemented yet" );
48 }
49  
50 # See:
51 # https://rt.cpan.org/Public/Bug/Display.html?id=132759
52 sub _calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc
53 {
54 8 ▶ return XML::LibXML->new( expand_entities => 1, );
Subroutine _calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc: called CC=1 SCAR=0.0
55 }
56  
57 sub _parse_bytestream {
58 0 ▶ my ( $self, $fh ) = @_;
Subroutine _parse_bytestream: not called CC=2 SCAR=17.9
59 0 ▶ $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ParserOptions"}{"LibParser"} 0 0 0
60 0 $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_fh;
61 0 $self->{ParserOptions}{ParseFuncParam} = $fh;
62 0 $self->_parse;
63 0 return $self->end_document({});
64 }
65  
66 sub _parse_string {
67 37 ▶ my ( $self, $string ) = @_;
Subroutine _parse_string: called CC=2 SCAR=6.9
68 37 ▶ $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ParserOptions"}{"LibParser"} 7 30 37
69 37 $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_string;
70 37 $self->{ParserOptions}{ParseFuncParam} = $string;
71 37 $self->_parse;
72 34 return $self->end_document({});
73 }
74  
75 sub _parse_systemid {
76 1 ▶ my $self = shift;
Subroutine _parse_systemid: called CC=2 SCAR=7.0
77 1 ▶ $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ParserOptions"}{"LibParser"} 0 1 1
78 1 $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_file;
79 1 $self->{ParserOptions}{ParseFuncParam} = shift;
80 1 $self->_parse;
81 1 return $self->end_document({});
82 }
83  
84 sub parse_chunk {
85 2 ▶ my ( $self, $chunk ) = @_;
Subroutine parse_chunk: called CC=2 SCAR=6.9
Pod undocumented
86 2 ▶ $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ParserOptions"}{"LibParser"} 1 1 2
87 2 $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_xml_chunk;
88 2 $self->{ParserOptions}{LibParser}->{IS_FILTER}=1; # a hack to prevent parse_xml_chunk from issuing end_document
89 2 $self->{ParserOptions}{ParseFuncParam} = $chunk;
90 2 $self->_parse;
91 2 return;
92 }
93  
94 sub _parse {
95 40 ▶ my $self = shift;
Subroutine _parse: called CC=4 SCAR=14.2
96 40 my $args = bless $self->{ParserOptions}, ref($self);
97  
98 40 ▶ if (defined($self->{JOIN_CHARACTERS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'JOIN_CHARACTERS'}) { } 0 40 40
99 0 $args->{LibParser}->{JOIN_CHARACTERS} = $self->{JOIN_CHARACTERS};
100 } else {
101 40 $args->{LibParser}->{JOIN_CHARACTERS} = 0;
102 }
103  
104 40 $args->{LibParser}->set_handler( $self );
105 40 eval {
106 40 $args->{ParseFunc}->($args->{LibParser}, $args->{ParseFuncParam});
107 };
108  
109 40 ▶ if ( $args->{LibParser}->{SAX}->{State} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"LibParser"}{"SAX"}{"State"} == 1) 0 40 40
110 0 croak( "SAX Exception not implemented, yet; Data ended before document ended\n" );
111 }
112  
113 # break a possible circular reference
114 40 $args->{LibParser}->set_handler( undef );
115 40 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 37 40
116 3 croak $@;
117 }
118 37 return;
119 }
120  
121 3 1;
122  
« blib/lib/XML/LibXML/NodeList.pm ↑ Summary blib/lib/XML/LibXML/Number.pm »