blib/lib/XML/LibXML/Reader.pm

filter: Statementstmt 89.1% 82 / 92 Branchbran 73.6% 28 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.2% 15 / 17 Podpod 83.3% 5 / 6 totaltotal 84.9% 130 / 153 CC 20 SCAR 19.8
CC
20
Cov
85%
new
14.1
setParserProp
12.0
BEGIN
2.1
CRAP 7.3
« blib/lib/XML/LibXML/SAX/Builder.pm ↑ Summary blib/lib/XML/LibXML.pm »
1 # $Id: Reader.pm,v 1.1.2.1 2004/04/20 20:09:48 pajas Exp $
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 package XML::LibXML::Reader;
10  
11 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 our $VERSION = "2.0213"; # VERSION TEMPLATE: DO NOT CHANGE
17  
18 4 ▶use 5.008_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
21 4 ▶ UNIVERSAL::can('XML::LibXML::Reader','_newForFile') or
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can("XML::LibXML::Reader", "_newForFile") or croak("Cannot use XML::LibXML::Reader module - your libxml2 is compiled without reader support!") 4 0 4
22 croak("Cannot use XML::LibXML::Reader module - ".
23 "your libxml2 is compiled without reader support!");
24 }
25  
26 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 XML_READER_TYPE_NONE => 0,
29 XML_READER_TYPE_ELEMENT => 1,
30 XML_READER_TYPE_ATTRIBUTE => 2,
31 XML_READER_TYPE_TEXT => 3,
32 XML_READER_TYPE_CDATA => 4,
33 XML_READER_TYPE_ENTITY_REFERENCE => 5,
34 XML_READER_TYPE_ENTITY => 6,
35 XML_READER_TYPE_PROCESSING_INSTRUCTION => 7,
36 XML_READER_TYPE_COMMENT => 8,
37 XML_READER_TYPE_DOCUMENT => 9,
38 XML_READER_TYPE_DOCUMENT_TYPE => 10,
39 XML_READER_TYPE_DOCUMENT_FRAGMENT => 11,
40 XML_READER_TYPE_NOTATION => 12,
41 XML_READER_TYPE_WHITESPACE => 13,
42 XML_READER_TYPE_SIGNIFICANT_WHITESPACE => 14,
43 XML_READER_TYPE_END_ELEMENT => 15,
44 XML_READER_TYPE_END_ENTITY => 16,
45 XML_READER_TYPE_XML_DECLARATION => 17,
46  
47 XML_READER_NONE => -1,
48 XML_READER_START => 0,
49 XML_READER_ELEMENT => 1,
50 XML_READER_END => 2,
51 XML_READER_EMPTY => 3,
52 XML_READER_BACKTRACK => 4,
53 XML_READER_DONE => 5,
54 XML_READER_ERROR => 6
55 4 };
56  
57 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
58  
59 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 4 our %EXPORT_TAGS = (
62 types =>
63 [qw(
64 XML_READER_TYPE_NONE
65 XML_READER_TYPE_ELEMENT
66 XML_READER_TYPE_ATTRIBUTE
67 XML_READER_TYPE_TEXT
68 XML_READER_TYPE_CDATA
69 XML_READER_TYPE_ENTITY_REFERENCE
70 XML_READER_TYPE_ENTITY
71 XML_READER_TYPE_PROCESSING_INSTRUCTION
72 XML_READER_TYPE_COMMENT
73 XML_READER_TYPE_DOCUMENT
74 XML_READER_TYPE_DOCUMENT_TYPE
75 XML_READER_TYPE_DOCUMENT_FRAGMENT
76 XML_READER_TYPE_NOTATION
77 XML_READER_TYPE_WHITESPACE
78 XML_READER_TYPE_SIGNIFICANT_WHITESPACE
79 XML_READER_TYPE_END_ELEMENT
80 XML_READER_TYPE_END_ENTITY
81 XML_READER_TYPE_XML_DECLARATION
82 )],
83 states =>
84 [qw(
85 XML_READER_NONE
86 XML_READER_START
87 XML_READER_ELEMENT
88 XML_READER_END
89 XML_READER_EMPTY
90 XML_READER_BACKTRACK
91 XML_READER_DONE
92 XML_READER_ERROR
93 )]
94 );
95 4 our @EXPORT = (@{$EXPORT_TAGS{types}},@{$EXPORT_TAGS{states}});
96 4 our @EXPORT_OK = @EXPORT;
97 4 $EXPORT_TAGS{all}=\@EXPORT_OK;
98 }
99  
100 4 our %_preserve_flag;
101  
102 {
103 4 my %props = (
104 load_ext_dtd => 1, # load the external subset
105 complete_attributes => 2, # default DTD attributes
106 validation => 3, # validate with the DTD
107 expand_entities => 4, # substitute entities
108 );
109 1 ▶ sub getParserProp {
Subroutine getParserProp: called CC=2 SCAR=7.0
Pod documented
110 1 my ($self, $name) = @_;
111 1 my $prop = $props{$name};
112 1 ▶ return undef unless defined $prop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prop 0 1 1
113 1 return $self->_getParserProp($prop);
114 }
115 0 ▶ sub setParserProp {
Subroutine setParserProp: not called CC=3 SCAR=24.8
Pod documented
116 0 my $self = shift;
117 0 ▶ my %args = map { ref($_) eq 'HASH' ? (%$_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 0 0
118 0 my ($key, $value);
119 0 ▶ while (($key,$value) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
120 0 my $prop = $props{ $key };
121 0 $self->_setParserProp($prop,$value);
122 }
123 0 return;
124 }
125  
126 4 my (%string_pool,%rng_pool,%xsd_pool); # used to preserve data passed to the reader
127 31 ▶ sub new {
Subroutine new: called CC=14 SCAR=26.4
Pod undocumented
128 31 my ($class) = shift;
129 31 ▶ my %args = map { ref($_) eq 'HASH' ? (%$_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 1 98 99
130 31 my $encoding = $args{encoding};
131 31 my $URI = $args{URI};
132 31 ▶ $URI="$URI" if defined $URI; # stringify in case it is an URI object
Branch: 1 branch
BranchTrueFalseTotal
if defined $URI 4 27 31
133 31 my $options = XML::LibXML->_parser_options(\%args);
134  
135 31 my $self = undef;
136 31 ▶ if ( defined $args{location} ) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $args{'location'}) { } 9 22 31
elsif (defined $args{'string'}) { } 19 3 22
elsif (defined $args{'IO'}) { } 1 2 3
elsif (defined $args{'DOM'}) { } 1 1 2
elsif (defined $args{'FD'}) { } 1 0 1
137 9 $self = $class->_newForFile( $args{location}, $encoding, $options );
138 }
139 elsif ( defined $args{string} ) {
140 19 $self = $class->_newForString( $args{string}, $URI, $encoding, $options );
141 19 ▶ if (defined($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) 19 0 19
142 19 $string_pool{$self} = \$args{string};
143 }
144 }
145 elsif ( defined $args{IO} ) {
146 1 $self = $class->_newForIO( $args{IO}, $URI, $encoding, $options );
147 }
148 elsif ( defined $args{DOM} ) {
149 croak("DOM must be a XML::LibXML::Document node")
150 1 ▶ unless UNIVERSAL::isa($args{DOM}, 'XML::LibXML::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($args{"DOM"}, "XML::LibXML::Document") 0 1 1
151 1 $self = $class->_newForDOM( $args{DOM} );
152 }
153 elsif ( defined $args{FD} ) {
154 1 my $fd = fileno($args{FD});
155 1 $self = $class->_newForFd( $fd, $URI, $encoding, $options );
156 }
157 else {
158 0 croak("XML::LibXML::Reader->new: specify location, string, IO, DOM, or FD");
159 }
160 31 ▶ if ($args{RelaxNG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"RelaxNG"}) 4 27 31
161 4 ▶ if (ref($args{RelaxNG})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'RelaxNG'}) { } 2 2 4
162 2 $rng_pool{$self} = \$args{RelaxNG};
163 2 $self->_setRelaxNG($args{RelaxNG});
164 } else {
165 2 $self->_setRelaxNGFile($args{RelaxNG});
166 }
167 }
168 31 ▶ if ($args{Schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Schema"}) 4 27 31
169 4 ▶ if (ref($args{Schema})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'Schema'}) { } 2 2 4
170 2 $xsd_pool{$self} = \$args{Schema};
171 2 $self->_setXSD($args{Schema});
172 } else {
173 2 $self->_setXSDFile($args{Schema});
174 }
175 }
176 31 return $self;
177 }
178 31 ▶ sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
179 31 my $self = shift;
180 31 delete $string_pool{$self};
181 31 delete $rng_pool{$self};
182 31 delete $xsd_pool{$self};
183 31 $self->_DESTROY;
184 }
185 }
186 4 ▶sub close {
Subroutine close: called CC=2 SCAR=7.1
Pod documented
187 1 my ($reader) = @_;
188 # _close return -1 on failure, 0 on success
189 # perl close returns 0 on failure, 1 on success
190 1 ▶ return $reader->_close == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$reader->_close == 0 ? : 1 0 1
191 }
192  
193 2 ▶sub preservePattern {
Subroutine preservePattern: called CC=2 SCAR=6.9
Pod documented
194 2 my $reader=shift;
195 2 my ($pattern,$ns_map)=@_;
196 2 ▶ if (ref($ns_map) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns_map eq 'HASH') { } 1 1 2
197 # translate prefix=>URL hash to a (URL,prefix) list
198 1 $reader->_preservePattern($pattern,[reverse %$ns_map]);
199 } else {
200 1 $reader->_preservePattern(@_);
201 }
202 }
203  
204 8 ▶sub nodePath {
Subroutine nodePath: called CC=1 SCAR=0.0
Pod documented
205 8 my $reader=shift;
206 8 my $path = $reader->_nodePath;
207 8 $path=~s/\[\d+\]//g; # make /foo[1]/bar[1] just /foo/bar, since
208 # sibling count in the buffered fragment is
209 # basically random and generally misleading
210 8 return $path;
211 }
212  
213 4 1;
214 __END__
« blib/lib/XML/LibXML/SAX/Builder.pm ↑ Summary blib/lib/XML/LibXML.pm »