| 1 | 4 | ▶ | use 5.006; # our | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package IO::Async::XMLStream::SAXReader; | ||||||||||
| 6 | |||||||||||
| 7 | 4 | our $VERSION = '0.001001'; | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Dispatch SAX events from an XML stream. | ||||||||||
| 10 | |||||||||||
| 11 | 4 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | 4 | ▶ | use parent 'IO::Async::Stream'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | 4 | ▶ | use XML::LibXML::SAX::ChunkParser 0.00007; # Buggy Finish | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 4 | ▶ | use IO::Async::XMLStream::SAXReader::DuckHandler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | |||||||||||
| 70 | ## no critic (NamingConventions) | ||||||||||
| 71 | sub _SAXReader { | ||||||||||
| 72 | 30 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_SAXReader: called CC=2 SCAR=6.9
| |||||||||||
| 73 | 30 | my $key = 'SAXReader'; | |||||||||
| 74 | 30 | ▶ | return $self->{$key} if exists $self->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 3 | $self->{$key} = {}; | |||||||||
| 76 | 3 | $self->{$key}->{Parser} = XML::LibXML::SAX::ChunkParser->new( Handler => $self->{sax_handler} ); | |||||||||
| 77 | 3 | return $self->{$key}; | |||||||||
| 78 | } | ||||||||||
| 79 | ## use critic | ||||||||||
| 80 | |||||||||||
| 81 | 4 | my @XML_METHODS = qw( | |||||||||
| 82 | attlist_decl | ||||||||||
| 83 | attribute_decl | ||||||||||
| 84 | characters | ||||||||||
| 85 | comment | ||||||||||
| 86 | doctype_decl | ||||||||||
| 87 | element_decl | ||||||||||
| 88 | end_cdata | ||||||||||
| 89 | end_document | ||||||||||
| 90 | end_dtd | ||||||||||
| 91 | end_element | ||||||||||
| 92 | end_entity | ||||||||||
| 93 | end_prefix_mapping | ||||||||||
| 94 | entity_decl | ||||||||||
| 95 | entity_reference | ||||||||||
| 96 | error | ||||||||||
| 97 | external_entity_decl | ||||||||||
| 98 | fatal_error | ||||||||||
| 99 | ignorable_whitespace | ||||||||||
| 100 | internal_entity_decl | ||||||||||
| 101 | notation_decl | ||||||||||
| 102 | processing_instruction | ||||||||||
| 103 | resolve_entity | ||||||||||
| 104 | set_document_locator | ||||||||||
| 105 | skipped_entity | ||||||||||
| 106 | start_cdata | ||||||||||
| 107 | start_document | ||||||||||
| 108 | start_dtd | ||||||||||
| 109 | start_element | ||||||||||
| 110 | start_entity | ||||||||||
| 111 | start_prefix_mapping | ||||||||||
| 112 | unparsed_entity_decl | ||||||||||
| 113 | warning | ||||||||||
| 114 | xml_decl | ||||||||||
| 115 | ); | ||||||||||
| 116 | |||||||||||
| 117 | sub configure { | ||||||||||
| 118 | 3 | ▶ | my ( $self, %params ) = @_; | ||||||||
|
Subroutine
configure: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 119 | |||||||||||
| 120 | 3 | for my $method ('sax_handler') { | |||||||||
| 121 | 3 | ▶ | next unless exists $params{$method}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 1 | $self->{$method} = delete $params{$method}; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 3 | ▶ | if ( not $self->{'sax_handler'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 2 | $self->{'sax_handler'} = IO::Async::XMLStream::SAXReader::DuckHandler->new( { SAXReader => $self, }, ); | |||||||||
| 127 | 2 | for my $method (@XML_METHODS) { | |||||||||
| 128 | 66 | ▶ | next unless exists $params{ 'on_' . $method }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | 4 | $self->{ 'on_' . $method } = delete $params{ 'on_' . $method }; | |||||||||
| 130 | } | ||||||||||
| 131 | } | ||||||||||
| 132 | 3 | $self->_SAXReader; | |||||||||
| 133 | 3 | return $self->SUPER::configure(%params); | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | sub on_read { | ||||||||||
| 137 | 27 | ▶ | my ( $self, $buffref, $eof ) = @_; | ||||||||
|
Subroutine
on_read: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 138 | 27 | my $text = substr ${$buffref}, 0, length ${$buffref}, q[]; | |||||||||
| 139 | |||||||||||
| 140 | 27 | ▶ | $self->_SAXReader->{Parser}->parse_chunk($text) if length $text; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 27 | ▶ | if ($eof) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 3 | $self->_SAXReader->{Parser}->finish; | |||||||||
| 143 | 3 | return 0; | |||||||||
| 144 | } | ||||||||||
| 145 | 24 | return 1; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 4 | 1; | |||||||||
| 149 | |||||||||||
| 150 | __END__ | ||||||||||