| 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 | our $VERSION = "2.0213"; # VERSION TEMPLATE: DO NOT CHANGE | |||||||||
| 16 | |||||||||||
| 17 | 3 | ▶ | use XML::LibXML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 3 | ▶ | use XML::SAX::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | use parent qw(XML::SAX::Base); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 3 | ▶ | use IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub CLONE_SKIP { | ||||||||
|
Subroutine
CLONE_SKIP: not called CC=2 SCAR=17.9
| |||||||||||
| 26 | 0 | ▶ | return $XML::LibXML::__threads_shared ? 0 : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 8 | ▶ | sub set_feature { | ||||||||
|
Subroutine
set_feature: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||
| 30 | 8 | my ($self, $feat, $val) = @_; | |||||||||
| 31 | |||||||||||
| 32 | 8 | ▶ | if ($feat eq 'http://xmlns.perl.org/sax/join-character-data') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | $self->{JOIN_CHARACTERS} = $val; | |||||||||
| 34 | 0 | return 1; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 8 | shift(@_); | |||||||||
| 38 | 8 | return $self->SUPER::set_feature(@_); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub _parse_characterstream { | ||||||||
|
Subroutine
_parse_characterstream: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 0 | my ( $self, $fh ) = @_; | |||||||||
| 43 | # this my catch the xml decl, so the parser won't get confused about | ||||||||||
| 44 | # a possibly wrong encoding. | ||||||||||
| 45 | 0 | croak( "not implemented yet" ); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | # See: | ||||||||||
| 49 | # https://rt.cpan.org/Public/Bug/Display.html?id=132759 | ||||||||||
| 50 | sub _calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc | ||||||||||
| 51 | 8 | ▶ | { | ||||||||
|
Subroutine
_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 8 | return XML::LibXML->new( expand_entities => 1, ); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub _parse_bytestream { | ||||||||
|
Subroutine
_parse_bytestream: not called CC=2 SCAR=17.9
| |||||||||||
| 56 | 0 | my ( $self, $fh ) = @_; | |||||||||
| 57 | 0 | ▶ | $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_fh; | |||||||||
| 59 | 0 | $self->{ParserOptions}{ParseFuncParam} = $fh; | |||||||||
| 60 | 0 | $self->_parse; | |||||||||
| 61 | 0 | return $self->end_document({}); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 37 | ▶ | sub _parse_string { | ||||||||
|
Subroutine
_parse_string: called CC=2 SCAR=6.9
| |||||||||||
| 65 | 37 | my ( $self, $string ) = @_; | |||||||||
| 66 | 37 | ▶ | $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 37 | $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_string; | |||||||||
| 68 | 37 | $self->{ParserOptions}{ParseFuncParam} = $string; | |||||||||
| 69 | 37 | $self->_parse; | |||||||||
| 70 | 34 | return $self->end_document({}); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | sub _parse_systemid { | ||||||||
|
Subroutine
_parse_systemid: called CC=2 SCAR=7.0
| |||||||||||
| 74 | 1 | my $self = shift; | |||||||||
| 75 | 1 | ▶ | $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 1 | $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_file; | |||||||||
| 77 | 1 | $self->{ParserOptions}{ParseFuncParam} = shift; | |||||||||
| 78 | 1 | $self->_parse; | |||||||||
| 79 | 1 | return $self->end_document({}); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 2 | ▶ | sub parse_chunk { | ||||||||
|
Subroutine
parse_chunk: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 83 | 2 | my ( $self, $chunk ) = @_; | |||||||||
| 84 | 2 | ▶ | $self->{ParserOptions}{LibParser} = $self->_calc_new_XML_LibXML_parser_for_compatibility_with_XML_Simple_etc() unless defined $self->{ParserOptions}{LibParser}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 2 | $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_xml_chunk; | |||||||||
| 86 | 2 | $self->{ParserOptions}{LibParser}->{IS_FILTER}=1; # a hack to prevent parse_xml_chunk from issuing end_document | |||||||||
| 87 | 2 | $self->{ParserOptions}{ParseFuncParam} = $chunk; | |||||||||
| 88 | 2 | $self->_parse; | |||||||||
| 89 | 2 | return; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 40 | ▶ | sub _parse { | ||||||||
|
Subroutine
_parse: called CC=4 SCAR=14.2
| |||||||||||
| 93 | 40 | my $self = shift; | |||||||||
| 94 | 40 | my $args = bless $self->{ParserOptions}, ref($self); | |||||||||
| 95 | |||||||||||
| 96 | 40 | ▶ | if (defined($self->{JOIN_CHARACTERS})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | $args->{LibParser}->{JOIN_CHARACTERS} = $self->{JOIN_CHARACTERS}; | |||||||||
| 98 | } else { | ||||||||||
| 99 | 40 | $args->{LibParser}->{JOIN_CHARACTERS} = 0; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 40 | $args->{LibParser}->set_handler( $self ); | |||||||||
| 103 | 40 | eval { | |||||||||
| 104 | 40 | $args->{ParseFunc}->($args->{LibParser}, $args->{ParseFuncParam}); | |||||||||
| 105 | }; | ||||||||||
| 106 | |||||||||||
| 107 | 40 | ▶ | if ( $args->{LibParser}->{SAX}->{State} == 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | croak( "SAX Exception not implemented, yet; Data ended before document ended\n" ); | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | # break a possible circular reference | ||||||||||
| 112 | 40 | $args->{LibParser}->set_handler( undef ); | |||||||||
| 113 | 40 | ▶ | if ( $@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 3 | croak $@; | |||||||||
| 115 | } | ||||||||||
| 116 | 37 | return; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 3 | 1; | |||||||||
| 120 | |||||||||||