lib/IO/Async/XMLStream/SAXReader.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 74 / 74 CC 9 SCAR 11.3
CC
9
Cov
100%
configure
6.0
on_read
3.0
_SAXReader
2.0
CRAP 3.1
« blib/lib/IO/Async/XMLStream/SAXReader/DuckHandler.pm ↑ Summary lib/IO/Async/XMLStream/SAXReader/DuckHandler.pm »
1 4 ▶use 5.008; # utf8
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 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package IO::Async::XMLStream::SAXReader;
7 4 $IO::Async::XMLStream::SAXReader::VERSION = '0.001000';
8 # ABSTRACT: Dispatch SAX events from an XML stream.
9  
10 4 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11  
12 4 ▶use parent 'IO::Async::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
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 4 ▶use XML::LibXML::SAX::ChunkParser 0.00007; # Buggy Finish
Subroutine BEGIN: called CC=1 SCAR=0.0
67 4 ▶use IO::Async::XMLStream::SAXReader::DuckHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 ## no critic (NamingConventions)
70 sub _SAXReader {
71 30 ▶ my ($self) = @_;
Subroutine _SAXReader: called CC=2 SCAR=6.9
72 30 my $key = 'SAXReader';
73 30 ▶ return $self->{$key} if exists $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$key} 27 3 30
74 3 $self->{$key} = {};
75 3 $self->{$key}->{Parser} = XML::LibXML::SAX::ChunkParser->new( Handler => $self->{sax_handler} );
76 3 return $self->{$key};
77 }
78 ## use critic
79  
80 4 my @XML_METHODS = qw(
81 attlist_decl
82 attribute_decl
83 characters
84 comment
85 doctype_decl
86 element_decl
87 end_cdata
88 end_document
89 end_dtd
90 end_element
91 end_entity
92 end_prefix_mapping
93 entity_decl
94 entity_reference
95 error
96 external_entity_decl
97 fatal_error
98 ignorable_whitespace
99 internal_entity_decl
100 notation_decl
101 processing_instruction
102 resolve_entity
103 set_document_locator
104 skipped_entity
105 start_cdata
106 start_document
107 start_dtd
108 start_element
109 start_entity
110 start_prefix_mapping
111 unparsed_entity_decl
112 warning
113 xml_decl
114 );
115  
116 sub configure {
117 3 ▶ my ( $self, %params ) = @_;
Subroutine configure: called CC=6 SCAR=17.9
Pod documented
118  
119 3 for my $method ('sax_handler') {
120 3 ▶ next unless exists $params{$method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{$method} 2 1 3
121 1 $self->{$method} = delete $params{$method};
122 }
123  
124 3 ▶ if ( not $self->{'sax_handler'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sax_handler"}) 2 1 3
125 2 $self->{'sax_handler'} = IO::Async::XMLStream::SAXReader::DuckHandler->new( { SAXReader => $self, }, );
126 2 for my $method (@XML_METHODS) {
127 66 ▶ next unless exists $params{ 'on_' . $method };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{'on_' . $method} 62 4 66
128 4 $self->{ 'on_' . $method } = delete $params{ 'on_' . $method };
129 }
130 }
131 3 $self->_SAXReader;
132 3 return $self->SUPER::configure(%params);
133 }
134  
135 sub on_read {
136 27 ▶ my ( $self, $buffref, $eof ) = @_;
Subroutine on_read: called CC=3 SCAR=11.0
Pod documented
137 27 my $text = substr ${$buffref}, 0, length ${$buffref}, q[];
138  
139 27 ▶ $self->_SAXReader->{Parser}->parse_chunk($text) if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 24 3 27
140 27 ▶ if ($eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eof) 3 24 27
141 3 $self->_SAXReader->{Parser}->finish;
142 3 return 0;
143 }
144 24 return 1;
145 }
146  
147 4 1;
148  
149 __END__
« blib/lib/IO/Async/XMLStream/SAXReader/DuckHandler.pm ↑ Summary lib/IO/Async/XMLStream/SAXReader/DuckHandler.pm »