| Filename | /usr/share/perl5/XML/SAX/Expat.pm |
| Statements | Executed 4416 statements in 10.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.98ms | 3.46ms | XML::SAX::Expat::BEGIN@10 |
| 1 | 1 | 1 | 2.00ms | 7.69ms | XML::SAX::Expat::BEGIN@11 |
| 142 | 1 | 1 | 1.84ms | 4.64ms | XML::SAX::Expat::_handle_start |
| 478 | 1 | 1 | 1.14ms | 3.91ms | XML::SAX::Expat::_handle_char |
| 142 | 1 | 1 | 1.10ms | 2.02ms | XML::SAX::Expat::_handle_end |
| 46 | 1 | 1 | 123µs | 281µs | XML::SAX::Expat::_handle_comment |
| 2 | 1 | 1 | 54µs | 236µs | XML::SAX::Expat::_create_parser |
| 2 | 1 | 1 | 30µs | 16.5ms | XML::SAX::Expat::_parse_systemid |
| 6 | 2 | 1 | 21µs | 27µs | XML::SAX::Expat::supported_features |
| 8 | 1 | 1 | 19µs | 19µs | XML::SAX::Expat::CORE:match (opcode) |
| 2 | 1 | 1 | 12µs | 69µs | XML::SAX::Expat::_handle_start_document |
| 1 | 1 | 1 | 12µs | 22µs | XML::SAX::Expat::BEGIN@8 |
| 2 | 1 | 1 | 11µs | 52µs | XML::SAX::Expat::_handle_final |
| 1 | 1 | 1 | 8µs | 13.0ms | XML::SAX::Expat::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 25µs | XML::SAX::Expat::BEGIN@13 |
| 2 | 1 | 1 | 4µs | 4µs | XML::SAX::Expat::_cleanup |
| 2 | 1 | 1 | 3µs | 3µs | XML::SAX::Expat::_handle_init |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_attr_decl |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_element_decl |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_end_cdata |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_end_doctype |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_entity_decl |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_notation_decl |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_proc |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_start_cdata |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_start_doctype |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_unparsed_entity |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_handle_xml_decl |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_parse_bytestream |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_parse_characterstream |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::Expat::_parse_string |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | ### | ||||
| 3 | # XML::SAX::Expat - SAX2 Driver for Expat (XML::Parser) | ||||
| 4 | # Originally by Robin Berjon | ||||
| 5 | ### | ||||
| 6 | |||||
| 7 | package XML::SAX::Expat; | ||||
| 8 | 2 | 31µs | 2 | 33µs | # spent 22µs (12+11) within XML::SAX::Expat::BEGIN@8 which was called:
# once (12µs+11µs) by XML::SAX::ParserFactory::parser at line 8 # spent 22µs making 1 call to XML::SAX::Expat::BEGIN@8
# spent 11µs making 1 call to strict::import |
| 9 | 2 | 44µs | 2 | 26.0ms | # spent 13.0ms (8µs+13.0) within XML::SAX::Expat::BEGIN@9 which was called:
# once (8µs+13.0ms) by XML::SAX::ParserFactory::parser at line 9 # spent 13.0ms making 1 call to XML::SAX::Expat::BEGIN@9
# spent 13.0ms making 1 call to base::import |
| 10 | 2 | 1.45ms | 1 | 3.46ms | # spent 3.46ms (2.98+483µs) within XML::SAX::Expat::BEGIN@10 which was called:
# once (2.98ms+483µs) by XML::SAX::ParserFactory::parser at line 10 # spent 3.46ms making 1 call to XML::SAX::Expat::BEGIN@10 |
| 11 | 2 | 845µs | 1 | 7.69ms | # spent 7.69ms (2.00+5.69) within XML::SAX::Expat::BEGIN@11 which was called:
# once (2.00ms+5.69ms) by XML::SAX::ParserFactory::parser at line 11 # spent 7.69ms making 1 call to XML::SAX::Expat::BEGIN@11 |
| 12 | |||||
| 13 | 2 | 1.35ms | 2 | 42µs | # spent 25µs (8+17) within XML::SAX::Expat::BEGIN@13 which was called:
# once (8µs+17µs) by XML::SAX::ParserFactory::parser at line 13 # spent 25µs making 1 call to XML::SAX::Expat::BEGIN@13
# spent 17µs making 1 call to vars::import |
| 14 | 1 | 400ns | $VERSION = '0.40'; | ||
| 15 | |||||
| 16 | |||||
| 17 | #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# | ||||
| 18 | #`,`, Variations on parse `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# | ||||
| 19 | #```````````````````````````````````````````````````````````````````# | ||||
| 20 | |||||
| 21 | #-------------------------------------------------------------------# | ||||
| 22 | # CharacterStream | ||||
| 23 | #-------------------------------------------------------------------# | ||||
| 24 | sub _parse_characterstream { | ||||
| 25 | my $p = shift; | ||||
| 26 | my $xml = shift; | ||||
| 27 | my $opt = shift; | ||||
| 28 | |||||
| 29 | my $expat = $p->_create_parser($opt); | ||||
| 30 | my $result = $expat->parse($xml); | ||||
| 31 | $p->_cleanup; | ||||
| 32 | return $result; | ||||
| 33 | } | ||||
| 34 | #-------------------------------------------------------------------# | ||||
| 35 | |||||
| 36 | #-------------------------------------------------------------------# | ||||
| 37 | # ByteStream | ||||
| 38 | #-------------------------------------------------------------------# | ||||
| 39 | sub _parse_bytestream { | ||||
| 40 | my $p = shift; | ||||
| 41 | my $xml = shift; | ||||
| 42 | my $opt = shift; | ||||
| 43 | |||||
| 44 | my $expat = $p->_create_parser($opt); | ||||
| 45 | my $result = $expat->parse($xml); | ||||
| 46 | $p->_cleanup; | ||||
| 47 | return $result; | ||||
| 48 | } | ||||
| 49 | #-------------------------------------------------------------------# | ||||
| 50 | |||||
| 51 | #-------------------------------------------------------------------# | ||||
| 52 | # String | ||||
| 53 | #-------------------------------------------------------------------# | ||||
| 54 | sub _parse_string { | ||||
| 55 | my $p = shift; | ||||
| 56 | my $xml = shift; | ||||
| 57 | my $opt = shift; | ||||
| 58 | |||||
| 59 | my $expat = $p->_create_parser($opt); | ||||
| 60 | my $result = $expat->parse($xml); | ||||
| 61 | $p->_cleanup; | ||||
| 62 | return $result; | ||||
| 63 | } | ||||
| 64 | #-------------------------------------------------------------------# | ||||
| 65 | |||||
| 66 | #-------------------------------------------------------------------# | ||||
| 67 | # SystemId | ||||
| 68 | #-------------------------------------------------------------------# | ||||
| 69 | # spent 16.5ms (30µs+16.5) within XML::SAX::Expat::_parse_systemid which was called 2 times, avg 8.27ms/call:
# 2 times (30µs+16.5ms) by XML::SAX::Base::parse at line 2608 of XML/SAX/Base.pm, avg 8.27ms/call | ||||
| 70 | 2 | 600ns | my $p = shift; | ||
| 71 | 2 | 700ns | my $xml = shift; | ||
| 72 | 2 | 300ns | my $opt = shift; | ||
| 73 | |||||
| 74 | 2 | 3µs | 2 | 236µs | my $expat = $p->_create_parser($opt);
# spent 236µs making 2 calls to XML::SAX::Expat::_create_parser, avg 118µs/call |
| 75 | 2 | 4µs | 2 | 16.3ms | my $result = $expat->parsefile($xml);
# spent 16.3ms making 2 calls to XML::Parser::parsefile, avg 8.14ms/call |
| 76 | 2 | 3µs | 2 | 4µs | $p->_cleanup;
# spent 4µs making 2 calls to XML::SAX::Expat::_cleanup, avg 2µs/call |
| 77 | 2 | 14µs | return $result; | ||
| 78 | } | ||||
| 79 | #-------------------------------------------------------------------# | ||||
| 80 | |||||
| 81 | |||||
| 82 | #-------------------------------------------------------------------# | ||||
| 83 | # $p->_create_parser(\%options) | ||||
| 84 | #-------------------------------------------------------------------# | ||||
| 85 | # spent 236µs (54+182) within XML::SAX::Expat::_create_parser which was called 2 times, avg 118µs/call:
# 2 times (54µs+182µs) by XML::SAX::Expat::_parse_systemid at line 74, avg 118µs/call | ||||
| 86 | 2 | 300ns | my $self = shift; | ||
| 87 | 2 | 400ns | my $opt = shift; | ||
| 88 | |||||
| 89 | 2 | 600ns | die "ParserReference: parser instance ($self) already parsing\n" | ||
| 90 | if $self->{_InParse}; | ||||
| 91 | |||||
| 92 | 2 | 400ns | my $featUri = 'http://xml.org/sax/features/'; | ||
| 93 | 2 | 8µs | 4 | 68µs | my $ppe = ($self->get_feature($featUri . 'external-general-entities') or
# spent 68µs making 4 calls to XML::SAX::Base::get_feature, avg 17µs/call |
| 94 | $self->get_feature($featUri . 'external-parameter-entities') ) ? 1 : 0; | ||||
| 95 | |||||
| 96 | 2 | 6µs | 2 | 40µs | my $expat = XML::Parser->new( ParseParamEnt => $ppe );
# spent 40µs making 2 calls to XML::Parser::new, avg 20µs/call |
| 97 | 2 | 3µs | $expat->{__XSE} = $self; | ||
| 98 | 2 | 9µs | 2 | 58µs | $expat->setHandlers(
# spent 58µs making 2 calls to XML::Parser::setHandlers, avg 29µs/call |
| 99 | Init => \&_handle_init, | ||||
| 100 | Final => \&_handle_final, | ||||
| 101 | Start => \&_handle_start, | ||||
| 102 | End => \&_handle_end, | ||||
| 103 | Char => \&_handle_char, | ||||
| 104 | Comment => \&_handle_comment, | ||||
| 105 | Proc => \&_handle_proc, | ||||
| 106 | CdataStart => \&_handle_start_cdata, | ||||
| 107 | CdataEnd => \&_handle_end_cdata, | ||||
| 108 | Unparsed => \&_handle_unparsed_entity, | ||||
| 109 | Notation => \&_handle_notation_decl, | ||||
| 110 | #ExternEnt | ||||
| 111 | #ExternEntFin | ||||
| 112 | Entity => \&_handle_entity_decl, | ||||
| 113 | Element => \&_handle_element_decl, | ||||
| 114 | Attlist => \&_handle_attr_decl, | ||||
| 115 | Doctype => \&_handle_start_doctype, | ||||
| 116 | DoctypeFin => \&_handle_end_doctype, | ||||
| 117 | XMLDecl => \&_handle_xml_decl, | ||||
| 118 | ); | ||||
| 119 | |||||
| 120 | 2 | 800ns | $self->{_InParse} = 1; | ||
| 121 | 2 | 1µs | $self->{_NodeStack} = []; | ||
| 122 | 2 | 1µs | $self->{_NSStack} = []; | ||
| 123 | 2 | 9µs | 2 | 16µs | $self->{_NSHelper} = XML::NamespaceSupport->new({xmlns => 1});
# spent 16µs making 2 calls to XML::NamespaceSupport::new, avg 8µs/call |
| 124 | 2 | 2µs | $self->{_started} = 0; | ||
| 125 | |||||
| 126 | 2 | 5µs | return $expat; | ||
| 127 | } | ||||
| 128 | #-------------------------------------------------------------------# | ||||
| 129 | |||||
| 130 | |||||
| 131 | #-------------------------------------------------------------------# | ||||
| 132 | # $p->_cleanup | ||||
| 133 | #-------------------------------------------------------------------# | ||||
| 134 | # spent 4µs within XML::SAX::Expat::_cleanup which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by XML::SAX::Expat::_parse_systemid at line 76, avg 2µs/call | ||||
| 135 | 2 | 500ns | my $self = shift; | ||
| 136 | |||||
| 137 | 2 | 1µs | $self->{_InParse} = 0; | ||
| 138 | 2 | 5µs | delete $self->{_NodeStack}; | ||
| 139 | } | ||||
| 140 | #-------------------------------------------------------------------# | ||||
| 141 | |||||
| 142 | |||||
| 143 | |||||
| 144 | #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# | ||||
| 145 | #`,`, Expat Handlers ,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# | ||||
| 146 | #```````````````````````````````````````````````````````````````````# | ||||
| 147 | |||||
| 148 | #-------------------------------------------------------------------# | ||||
| 149 | # _handle_init | ||||
| 150 | #-------------------------------------------------------------------# | ||||
| 151 | 2 | 6µs | # spent 3µs within XML::SAX::Expat::_handle_init which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by XML::Parser::parse at line 181 of XML/Parser.pm, avg 1µs/call | ||
| 152 | #my $self = shift()->{__XSE}; | ||||
| 153 | |||||
| 154 | #my $document = {}; | ||||
| 155 | #push @{$self->{_NodeStack}}, $document; | ||||
| 156 | #$self->SUPER::start_document($document); | ||||
| 157 | } | ||||
| 158 | #-------------------------------------------------------------------# | ||||
| 159 | |||||
| 160 | #-------------------------------------------------------------------# | ||||
| 161 | # _handle_final | ||||
| 162 | #-------------------------------------------------------------------# | ||||
| 163 | # spent 52µs (11+42) within XML::SAX::Expat::_handle_final which was called 2 times, avg 26µs/call:
# 2 times (11µs+42µs) by XML::Parser::parse at line 200 of XML/Parser.pm, avg 26µs/call | ||||
| 164 | 2 | 900ns | my $self = shift()->{__XSE}; | ||
| 165 | |||||
| 166 | #my $document = pop @{$self->{_NodeStack}}; | ||||
| 167 | 2 | 11µs | 2 | 42µs | return $self->SUPER::end_document({});
# spent 42µs making 2 calls to XML::SAX::Base::end_document, avg 21µs/call |
| 168 | } | ||||
| 169 | #-------------------------------------------------------------------# | ||||
| 170 | |||||
| 171 | #-------------------------------------------------------------------# | ||||
| 172 | # _handle_start | ||||
| 173 | #-------------------------------------------------------------------# | ||||
| 174 | # spent 4.64ms (1.84+2.80) within XML::SAX::Expat::_handle_start which was called 142 times, avg 33µs/call:
# 142 times (1.84ms+2.80ms) by XML::Parser::Expat::ParseStream at line 470 of XML/Parser/Expat.pm, avg 33µs/call | ||||
| 175 | 142 | 43µs | my $self = shift()->{__XSE}; | ||
| 176 | 142 | 20µs | my $e_name = shift; | ||
| 177 | 142 | 79µs | my %attr = @_; | ||
| 178 | |||||
| 179 | # start_document data | ||||
| 180 | 142 | 27µs | 2 | 69µs | $self->_handle_start_document({}) unless $self->{_started};
# spent 69µs making 2 calls to XML::SAX::Expat::_handle_start_document, avg 34µs/call |
| 181 | |||||
| 182 | # take care of namespaces | ||||
| 183 | 142 | 19µs | my $nsh = $self->{_NSHelper}; | ||
| 184 | 142 | 123µs | 142 | 335µs | $nsh->push_context;
# spent 335µs making 142 calls to XML::NamespaceSupport::push_context, avg 2µs/call |
| 185 | 142 | 14µs | my @new_ns; | ||
| 186 | 142 | 176µs | for my $k (grep !index($_, 'xmlns'), keys %attr) { | ||
| 187 | 8 | 32µs | 8 | 19µs | $k =~ m/^xmlns(:(.*))?$/;
# spent 19µs making 8 calls to XML::SAX::Expat::CORE:match, avg 2µs/call |
| 188 | 8 | 9µs | my $prefix = $2 || ''; | ||
| 189 | 8 | 12µs | 8 | 49µs | $nsh->declare_prefix($prefix, $attr{$k});
# spent 49µs making 8 calls to XML::NamespaceSupport::declare_prefix, avg 6µs/call |
| 190 | 8 | 12µs | my $ns = { | ||
| 191 | Prefix => $prefix, | ||||
| 192 | NamespaceURI => $attr{$k}, | ||||
| 193 | }; | ||||
| 194 | 8 | 3µs | push @new_ns, $ns; | ||
| 195 | 8 | 19µs | 8 | 53µs | $self->SUPER::start_prefix_mapping($ns);
# spent 53µs making 8 calls to XML::SAX::Base::start_prefix_mapping, avg 7µs/call |
| 196 | } | ||||
| 197 | 142 | 90µs | push @{$self->{_NSStack}}, \@new_ns; | ||
| 198 | |||||
| 199 | |||||
| 200 | # create the attributes | ||||
| 201 | 142 | 13µs | my %saxattr; | ||
| 202 | 56 | 55µs | 56 | 322µs | map {
# spent 322µs making 56 calls to XML::NamespaceSupport::process_attribute_name, avg 6µs/call |
| 203 | 142 | 60µs | my ($ns,$prefix,$lname) = $nsh->process_attribute_name($_); | ||
| 204 | 56 | 142µs | $saxattr{'{' . ($ns || '') . '}' . $lname} = { | ||
| 205 | Name => $_, | ||||
| 206 | LocalName => $lname || '', | ||||
| 207 | Prefix => $prefix || '', | ||||
| 208 | Value => $attr{$_}, | ||||
| 209 | NamespaceURI => $ns || '', | ||||
| 210 | }; | ||||
| 211 | } keys %attr; | ||||
| 212 | |||||
| 213 | |||||
| 214 | # now the element | ||||
| 215 | 142 | 132µs | 142 | 756µs | my ($ns,$prefix,$lname) = $nsh->process_element_name($e_name);
# spent 756µs making 142 calls to XML::NamespaceSupport::process_element_name, avg 5µs/call |
| 216 | 142 | 191µs | my $element = { | ||
| 217 | Name => $e_name, | ||||
| 218 | LocalName => $lname || '', | ||||
| 219 | Prefix => $prefix || '', | ||||
| 220 | NamespaceURI => $ns || '', | ||||
| 221 | Attributes => \%saxattr, | ||||
| 222 | }; | ||||
| 223 | |||||
| 224 | 142 | 37µs | push @{$self->{_NodeStack}}, $element; | ||
| 225 | 142 | 377µs | 142 | 1.20ms | $self->SUPER::start_element($element);
# spent 1.20ms making 142 calls to XML::SAX::Base::start_element, avg 8µs/call |
| 226 | } | ||||
| 227 | #-------------------------------------------------------------------# | ||||
| 228 | |||||
| 229 | #-------------------------------------------------------------------# | ||||
| 230 | # _handle_end | ||||
| 231 | #-------------------------------------------------------------------# | ||||
| 232 | # spent 2.02ms (1.10+914µs) within XML::SAX::Expat::_handle_end which was called 142 times, avg 14µs/call:
# 142 times (1.10ms+914µs) by XML::Parser::Expat::ParseStream at line 470 of XML/Parser/Expat.pm, avg 14µs/call | ||||
| 233 | 142 | 44µs | my $self = shift()->{__XSE}; | ||
| 234 | |||||
| 235 | 142 | 308µs | my %element = %{pop @{$self->{_NodeStack}}}; | ||
| 236 | 142 | 78µs | delete $element{Attributes}; | ||
| 237 | 142 | 147µs | 142 | 696µs | $self->SUPER::end_element(\%element);
# spent 696µs making 142 calls to XML::SAX::Base::end_element, avg 5µs/call |
| 238 | |||||
| 239 | 142 | 36µs | my $prev_ns = pop @{$self->{_NSStack}}; | ||
| 240 | 142 | 63µs | for my $ns (@$prev_ns) { | ||
| 241 | 8 | 25µs | 8 | 47µs | $self->SUPER::end_prefix_mapping( { %$ns } );
# spent 47µs making 8 calls to XML::SAX::Base::end_prefix_mapping, avg 6µs/call |
| 242 | } | ||||
| 243 | 142 | 334µs | 142 | 171µs | $self->{_NSHelper}->pop_context;
# spent 171µs making 142 calls to XML::NamespaceSupport::pop_context, avg 1µs/call |
| 244 | } | ||||
| 245 | #-------------------------------------------------------------------# | ||||
| 246 | |||||
| 247 | #-------------------------------------------------------------------# | ||||
| 248 | # _handle_char | ||||
| 249 | #-------------------------------------------------------------------# | ||||
| 250 | # spent 3.91ms (1.14+2.77) within XML::SAX::Expat::_handle_char which was called 478 times, avg 8µs/call:
# 478 times (1.14ms+2.77ms) by XML::Parser::Expat::ParseStream at line 470 of XML/Parser/Expat.pm, avg 8µs/call | ||||
| 251 | 478 | 154µs | $_[0]->{__XSE}->_handle_start_document({}) unless $_[0]->{__XSE}->{_started}; | ||
| 252 | 478 | 3.97ms | 478 | 2.77ms | $_[0]->{__XSE}->SUPER::characters({ Data => $_[1] });
# spent 2.77ms making 478 calls to XML::SAX::Base::characters, avg 6µs/call |
| 253 | } | ||||
| 254 | #-------------------------------------------------------------------# | ||||
| 255 | |||||
| 256 | #-------------------------------------------------------------------# | ||||
| 257 | # _handle_comment | ||||
| 258 | #-------------------------------------------------------------------# | ||||
| 259 | # spent 281µs (123+158) within XML::SAX::Expat::_handle_comment which was called 46 times, avg 6µs/call:
# 46 times (123µs+158µs) by XML::Parser::Expat::ParseStream at line 470 of XML/Parser/Expat.pm, avg 6µs/call | ||||
| 260 | 46 | 16µs | $_[0]->{__XSE}->_handle_start_document({}) unless $_[0]->{__XSE}->{_started}; | ||
| 261 | 46 | 93µs | 46 | 158µs | $_[0]->{__XSE}->SUPER::comment({ Data => $_[1] });
# spent 158µs making 46 calls to XML::SAX::Base::comment, avg 3µs/call |
| 262 | } | ||||
| 263 | #-------------------------------------------------------------------# | ||||
| 264 | |||||
| 265 | #-------------------------------------------------------------------# | ||||
| 266 | # _handle_proc | ||||
| 267 | #-------------------------------------------------------------------# | ||||
| 268 | sub _handle_proc { | ||||
| 269 | $_[0]->{__XSE}->_handle_start_document({}) unless $_[0]->{__XSE}->{_started}; | ||||
| 270 | $_[0]->{__XSE}->SUPER::processing_instruction({ Target => $_[1], Data => $_[2] }); | ||||
| 271 | } | ||||
| 272 | #-------------------------------------------------------------------# | ||||
| 273 | |||||
| 274 | #-------------------------------------------------------------------# | ||||
| 275 | # _handle_start_cdata | ||||
| 276 | #-------------------------------------------------------------------# | ||||
| 277 | sub _handle_start_cdata { | ||||
| 278 | $_[0]->{__XSE}->SUPER::start_cdata( {} ); | ||||
| 279 | } | ||||
| 280 | #-------------------------------------------------------------------# | ||||
| 281 | |||||
| 282 | #-------------------------------------------------------------------# | ||||
| 283 | # _handle_end_cdata | ||||
| 284 | #-------------------------------------------------------------------# | ||||
| 285 | sub _handle_end_cdata { | ||||
| 286 | $_[0]->{__XSE}->SUPER::end_cdata( {} ); | ||||
| 287 | } | ||||
| 288 | #-------------------------------------------------------------------# | ||||
| 289 | |||||
| 290 | #-------------------------------------------------------------------# | ||||
| 291 | # _handle_xml_decl | ||||
| 292 | #-------------------------------------------------------------------# | ||||
| 293 | sub _handle_xml_decl { | ||||
| 294 | my $self = shift()->{__XSE}; | ||||
| 295 | my $version = shift; | ||||
| 296 | my $encoding = shift; | ||||
| 297 | my $standalone = shift; | ||||
| 298 | |||||
| 299 | if (not defined $standalone) { $standalone = ''; } | ||||
| 300 | elsif ($standalone) { $standalone = 'yes'; } | ||||
| 301 | else { $standalone = 'no'; } | ||||
| 302 | my $xd = { | ||||
| 303 | Version => $version, | ||||
| 304 | Encoding => $encoding, | ||||
| 305 | Standalone => $standalone, | ||||
| 306 | }; | ||||
| 307 | #$self->SUPER::xml_decl($xd); | ||||
| 308 | $self->_handle_start_document($xd); | ||||
| 309 | } | ||||
| 310 | #-------------------------------------------------------------------# | ||||
| 311 | |||||
| 312 | #-------------------------------------------------------------------# | ||||
| 313 | # _handle_notation_decl | ||||
| 314 | #-------------------------------------------------------------------# | ||||
| 315 | sub _handle_notation_decl { | ||||
| 316 | my $self = shift()->{__XSE}; | ||||
| 317 | my $notation = shift; | ||||
| 318 | shift; | ||||
| 319 | my $system = shift; | ||||
| 320 | my $public = shift; | ||||
| 321 | |||||
| 322 | my $not = { | ||||
| 323 | Name => $notation, | ||||
| 324 | PublicId => $public, | ||||
| 325 | SystemId => $system, | ||||
| 326 | }; | ||||
| 327 | $self->SUPER::notation_decl($not); | ||||
| 328 | } | ||||
| 329 | #-------------------------------------------------------------------# | ||||
| 330 | |||||
| 331 | #-------------------------------------------------------------------# | ||||
| 332 | # _handle_unparsed_entity | ||||
| 333 | #-------------------------------------------------------------------# | ||||
| 334 | sub _handle_unparsed_entity { | ||||
| 335 | my $self = shift()->{__XSE}; | ||||
| 336 | my $name = shift; | ||||
| 337 | my $system = shift; | ||||
| 338 | my $public = shift; | ||||
| 339 | my $notation = shift; | ||||
| 340 | |||||
| 341 | my $ue = { | ||||
| 342 | Name => $name, | ||||
| 343 | PublicId => $public, | ||||
| 344 | SystemId => $system, | ||||
| 345 | Notation => $notation, | ||||
| 346 | }; | ||||
| 347 | $self->SUPER::unparsed_entity_decl($ue); | ||||
| 348 | } | ||||
| 349 | #-------------------------------------------------------------------# | ||||
| 350 | |||||
| 351 | #-------------------------------------------------------------------# | ||||
| 352 | # _handle_element_decl | ||||
| 353 | #-------------------------------------------------------------------# | ||||
| 354 | sub _handle_element_decl { | ||||
| 355 | $_[0]->{__XSE}->SUPER::element_decl({ Name => $_[1], Model => "$_[2]" }); | ||||
| 356 | } | ||||
| 357 | #-------------------------------------------------------------------# | ||||
| 358 | |||||
| 359 | |||||
| 360 | #-------------------------------------------------------------------# | ||||
| 361 | # _handle_attr_decl | ||||
| 362 | #-------------------------------------------------------------------# | ||||
| 363 | sub _handle_attr_decl { | ||||
| 364 | my $self = shift()->{__XSE}; | ||||
| 365 | my $ename = shift; | ||||
| 366 | my $aname = shift; | ||||
| 367 | my $type = shift; | ||||
| 368 | my $default = shift; | ||||
| 369 | my $fixed = shift; | ||||
| 370 | |||||
| 371 | my ($vd, $value); | ||||
| 372 | if ($fixed) { | ||||
| 373 | $vd = '#FIXED'; | ||||
| 374 | $default =~ s/^(?:"|')//; #" | ||||
| 375 | $default =~ s/(?:"|')$//; #" | ||||
| 376 | $value = $default; | ||||
| 377 | } | ||||
| 378 | else { | ||||
| 379 | if ($default =~ m/^#/) { | ||||
| 380 | $vd = $default; | ||||
| 381 | $value = ''; | ||||
| 382 | } | ||||
| 383 | else { | ||||
| 384 | $vd = ''; # maybe there's a default ? | ||||
| 385 | $default =~ s/^(?:"|')//; #" | ||||
| 386 | $default =~ s/(?:"|')$//; #" | ||||
| 387 | $value = $default; | ||||
| 388 | } | ||||
| 389 | } | ||||
| 390 | |||||
| 391 | my $at = { | ||||
| 392 | eName => $ename, | ||||
| 393 | aName => $aname, | ||||
| 394 | Type => $type, | ||||
| 395 | ValueDefault => $vd, | ||||
| 396 | Value => $value, | ||||
| 397 | }; | ||||
| 398 | $self->SUPER::attribute_decl($at); | ||||
| 399 | } | ||||
| 400 | #-------------------------------------------------------------------# | ||||
| 401 | |||||
| 402 | #-------------------------------------------------------------------# | ||||
| 403 | # _handle_entity_decl | ||||
| 404 | #-------------------------------------------------------------------# | ||||
| 405 | sub _handle_entity_decl { | ||||
| 406 | my $self = shift()->{__XSE}; | ||||
| 407 | my $name = shift; | ||||
| 408 | my $val = shift; | ||||
| 409 | my $sys = shift; | ||||
| 410 | my $pub = shift; | ||||
| 411 | my $ndata = shift; | ||||
| 412 | my $isprm = shift; | ||||
| 413 | |||||
| 414 | # deal with param ents | ||||
| 415 | if ($isprm) { | ||||
| 416 | $name = '%' . $name; | ||||
| 417 | } | ||||
| 418 | |||||
| 419 | # int vs ext | ||||
| 420 | if ($val) { | ||||
| 421 | my $ent = { | ||||
| 422 | Name => $name, | ||||
| 423 | Value => $val, | ||||
| 424 | }; | ||||
| 425 | $self->SUPER::internal_entity_decl($ent); | ||||
| 426 | } | ||||
| 427 | else { | ||||
| 428 | my $ent = { | ||||
| 429 | Name => $name, | ||||
| 430 | PublicId => $pub || '', | ||||
| 431 | SystemId => $sys, | ||||
| 432 | }; | ||||
| 433 | $self->SUPER::external_entity_decl($ent); | ||||
| 434 | } | ||||
| 435 | } | ||||
| 436 | #-------------------------------------------------------------------# | ||||
| 437 | |||||
| 438 | |||||
| 439 | #-------------------------------------------------------------------# | ||||
| 440 | # _handle_start_doctype | ||||
| 441 | #-------------------------------------------------------------------# | ||||
| 442 | sub _handle_start_doctype { | ||||
| 443 | my $self = shift()->{__XSE}; | ||||
| 444 | my $name = shift; | ||||
| 445 | my $sys = shift; | ||||
| 446 | my $pub = shift; | ||||
| 447 | |||||
| 448 | $self->_handle_start_document({}) unless $self->{_started}; | ||||
| 449 | |||||
| 450 | my $dtd = { | ||||
| 451 | Name => $name, | ||||
| 452 | SystemId => $sys, | ||||
| 453 | PublicId => $pub, | ||||
| 454 | }; | ||||
| 455 | $self->SUPER::start_dtd($dtd); | ||||
| 456 | } | ||||
| 457 | #-------------------------------------------------------------------# | ||||
| 458 | |||||
| 459 | #-------------------------------------------------------------------# | ||||
| 460 | # _handle_end_doctype | ||||
| 461 | #-------------------------------------------------------------------# | ||||
| 462 | sub _handle_end_doctype { | ||||
| 463 | $_[0]->{__XSE}->SUPER::end_dtd( {} ); | ||||
| 464 | } | ||||
| 465 | #-------------------------------------------------------------------# | ||||
| 466 | |||||
| 467 | |||||
| 468 | #-------------------------------------------------------------------# | ||||
| 469 | # _handle_start_document | ||||
| 470 | #-------------------------------------------------------------------# | ||||
| 471 | # spent 69µs (12+56) within XML::SAX::Expat::_handle_start_document which was called 2 times, avg 34µs/call:
# 2 times (12µs+56µs) by XML::SAX::Expat::_handle_start at line 180, avg 34µs/call | ||||
| 472 | 2 | 12µs | 2 | 56µs | $_[0]->SUPER::start_document($_[1]);
# spent 56µs making 2 calls to XML::SAX::Base::start_document, avg 28µs/call |
| 473 | 2 | 5µs | $_[0]->{_started} = 1; | ||
| 474 | } | ||||
| 475 | #-------------------------------------------------------------------# | ||||
| 476 | |||||
| 477 | |||||
| 478 | #-------------------------------------------------------------------# | ||||
| 479 | # supported_features | ||||
| 480 | #-------------------------------------------------------------------# | ||||
| 481 | # spent 27µs (21+6) within XML::SAX::Expat::supported_features which was called 6 times, avg 4µs/call:
# 4 times (10µs+3µs) by XML::SAX::Base::get_feature at line 2716 of XML/SAX/Base.pm, avg 3µs/call
# 2 times (11µs+3µs) by XML::SAX::Base::set_feature at line 2746 of XML/SAX/Base.pm, avg 7µs/call | ||||
| 482 | return ( | ||||
| 483 | 6 | 20µs | 6 | 6µs | $_[0]->SUPER::supported_features,
# spent 6µs making 6 calls to XML::SAX::Base::supported_features, avg 1µs/call |
| 484 | 'http://xml.org/sax/features/external-general-entities', | ||||
| 485 | 'http://xml.org/sax/features/external-parameter-entities', | ||||
| 486 | ); | ||||
| 487 | } | ||||
| 488 | #-------------------------------------------------------------------# | ||||
| 489 | |||||
| 490 | |||||
| 491 | |||||
| 492 | |||||
| 493 | |||||
| 494 | #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# | ||||
| 495 | #`,`, Private Helpers `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# | ||||
| 496 | #```````````````````````````````````````````````````````````````````# | ||||
| 497 | |||||
| 498 | #-------------------------------------------------------------------# | ||||
| 499 | # _create_node | ||||
| 500 | #-------------------------------------------------------------------# | ||||
| 501 | #sub _create_node { | ||||
| 502 | # shift; | ||||
| 503 | # # this may check for a factory later | ||||
| 504 | # return {@_}; | ||||
| 505 | #} | ||||
| 506 | #-------------------------------------------------------------------# | ||||
| 507 | |||||
| 508 | |||||
| 509 | 1 | 2µs | 1; | ||
| 510 | #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# | ||||
| 511 | #`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# | ||||
| 512 | #```````````````````````````````````````````````````````````````````# | ||||
| 513 | |||||
| 514 | =pod | ||||
| 515 | |||||
| 516 | =head1 NAME | ||||
| 517 | |||||
| 518 | XML::SAX::Expat - SAX2 Driver for Expat (XML::Parser) | ||||
| 519 | |||||
| 520 | =head1 SYNOPSIS | ||||
| 521 | |||||
| 522 | use XML::SAX::Expat; | ||||
| 523 | use XML::SAX::MyFooHandler; | ||||
| 524 | my $h = XML::SAX::MyFooHandler->new; | ||||
| 525 | my $p = XML::SAX::Expat->new(Handler => $h); | ||||
| 526 | $p->parse_file('/path/to/foo.xml'); | ||||
| 527 | |||||
| 528 | =head1 DESCRIPTION | ||||
| 529 | |||||
| 530 | This is an implementation of a SAX2 driver sitting on top of Expat | ||||
| 531 | (XML::Parser) which Ken MacLeod posted to perl-xml and which I have | ||||
| 532 | updated. | ||||
| 533 | |||||
| 534 | It is still incomplete, though most of the basic SAX2 events should be | ||||
| 535 | available. The SAX2 spec is currently available from | ||||
| 536 | http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/~checkout~/perl-xml/libxml-perl/doc/sax-2.0.html?rev=HEAD&content-type=text/html | ||||
| 537 | |||||
| 538 | A more friendly URL as well as a PODification of the spec are in the | ||||
| 539 | works. | ||||
| 540 | |||||
| 541 | =head1 METHODS | ||||
| 542 | |||||
| 543 | The methods defined in this class correspond to those listed in the | ||||
| 544 | PerlSAX2 specification, available above. | ||||
| 545 | |||||
| 546 | =head1 FEATURES AND CAVEATS | ||||
| 547 | |||||
| 548 | =over 2 | ||||
| 549 | |||||
| 550 | =item supported_features | ||||
| 551 | |||||
| 552 | Returns: | ||||
| 553 | |||||
| 554 | * http://xml.org/sax/features/external-general-entities | ||||
| 555 | * http://xml.org/sax/features/external-parameter-entities | ||||
| 556 | * [ Features supported by ancestors ] | ||||
| 557 | |||||
| 558 | Turning one of the first two on also turns the other on (this maps | ||||
| 559 | to the XML::Parser ParseParamEnts option). This may be fixed in the | ||||
| 560 | future, so don't rely on this behaviour. | ||||
| 561 | |||||
| 562 | =back | ||||
| 563 | |||||
| 564 | =head1 MISSING PARTS | ||||
| 565 | |||||
| 566 | XML::Parser has no listed callbacks for the following events, which | ||||
| 567 | are therefore not presently generated (ways may be found in the | ||||
| 568 | future): | ||||
| 569 | |||||
| 570 | * ignorable_whitespace | ||||
| 571 | * skipped_entity | ||||
| 572 | * start_entity / end_entity | ||||
| 573 | * resolve_entity | ||||
| 574 | |||||
| 575 | Ways of signalling them are welcome. In addition to those, | ||||
| 576 | set_document_locator is not yet called. | ||||
| 577 | |||||
| 578 | =head1 TODO | ||||
| 579 | |||||
| 580 | - reuse Ken's tests and add more | ||||
| 581 | |||||
| 582 | =head1 AUTHOR | ||||
| 583 | |||||
| 584 | Robin Berjon; stolen from Ken Macleod, ken@bitsko.slc.ut.us, and with | ||||
| 585 | suggestions and feedback from perl-xml. Currently maintained by Bjoern | ||||
| 586 | Hoehrmann L<http://bjoern.hoehrmann.de/>. | ||||
| 587 | |||||
| 588 | =head1 COPYRIGHT AND LICENSE | ||||
| 589 | |||||
| 590 | Copyright (c) 2001-2008 Robin Berjon. All rights reserved. This program is | ||||
| 591 | free software; you can redistribute it and/or modify it under the same | ||||
| 592 | terms as Perl itself. | ||||
| 593 | |||||
| 594 | =head1 SEE ALSO | ||||
| 595 | |||||
| 596 | XML::Parser::PerlSAX | ||||
| 597 | |||||
| 598 | =cut | ||||
# spent 19µs within XML::SAX::Expat::CORE:match which was called 8 times, avg 2µs/call:
# 8 times (19µs+0s) by XML::SAX::Expat::_handle_start at line 187, avg 2µs/call |