| File | /usr/local/lib/perl/5.10.0/XML/LibXML.pm |
| Statements Executed | 245 |
| Total Time | 0.0170095 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 2 | 4.19ms | 12.5ms | XML::LibXML::_parse_sax_file(xsub) |
| 5 | 5 | 4 | 1.89ms | 2.15ms | XML::LibXML::import |
| 1 | 1 | 2 | 1.06ms | 1.06ms | XML::LibXML::bootstrap(xsub) |
| 1 | 1 | 2 | 34µs | 34µs | XML::LibXML::LIBXML_RUNTIME_VERSION(xsub) |
| 1 | 1 | 2 | 28µs | 28µs | XML::LibXML::InputCallback::lib_init_callbacks(xsub) |
| 1 | 1 | 1 | 26µs | 26µs | XML::LibXML::new |
| 1 | 1 | 1 | 25µs | 117µs | XML::LibXML::_init_callbacks |
| 2 | 2 | 1 | 23µs | 23µs | XML::LibXML::set_handler |
| 1 | 1 | 1 | 21µs | 12.7ms | XML::LibXML::parse_file |
| 2 | 2 | 1 | 19µs | 19µs | XML::LibXML::match_callback |
| 1 | 1 | 1 | 15µs | 15µs | XML::LibXML::InputCallback::new |
| 1 | 1 | 1 | 13µs | 56µs | XML::LibXML::_cleanup_callbacks |
| 1 | 1 | 1 | 12µs | 40µs | XML::LibXML::InputCallback::init_callbacks |
| 1 | 1 | 1 | 12µs | 12µs | XML::LibXML::InputCallback::unregister_callbacks |
| 1 | 1 | 2 | 12µs | 12µs | XML::LibXML::LIBXML_VERSION(xsub) |
| 1 | 1 | 2 | 11µs | 11µs | XML::LibXML::InputCallback::lib_cleanup_callbacks(xsub) |
| 1 | 1 | 1 | 11µs | 22µs | XML::LibXML::InputCallback::cleanup_callbacks |
| 1 | 1 | 1 | 9µs | 9µs | XML::LibXML::open_callback |
| 1 | 1 | 1 | 8µs | 8µs | XML::LibXML::read_callback |
| 1 | 1 | 1 | 8µs | 8µs | XML::LibXML::threads_shared_enabled |
| 1 | 1 | 1 | 8µs | 8µs | XML::LibXML::close_callback |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Attr::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Attr::setNamespace |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::CDATASection::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::CLONE |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Comment::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::actualEncoding |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::insertPI |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::insertProcessingInstruction |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::process_xinclude |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::serialize |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::setDocumentElement |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Document::toString |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::DocumentFragment::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::DocumentFragment::toString |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Dtd::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::appendWellBalancedChunk |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getAttribute |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getAttributeNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getChildrenByLocalName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getChildrenByTagName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getChildrenByTagNameNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getElementsByLocalName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getElementsByTagName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::getElementsByTagNameNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::setAttribute |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::setAttributeNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Element::setNamespace |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::_callback_close |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::_callback_match |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::_callback_open |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::_callback_read |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::InputCallback::register_callbacks |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::getNamedItem |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::getNamedItemNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::item |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::length |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::new |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::nodes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::removeNamedItem |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::removeNamedItemNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::setNamedItem |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::NamedNodeMap::setNamedItemNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::getName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::getNamespaceURI |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::getNamespaces |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::getPrefix |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::isEqualNode |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::isSameNode |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::name |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::nodeName |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Namespace::prefix |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::attributes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::childNodes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::exists |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::find |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::findbool |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::findnodes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::findvalue |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::getChildNodes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::isSupported |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::setOwnerDocument |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::toStringC14N |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Node::toStringEC14N |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::PI::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::PI::setData |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Pattern::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Pattern::new |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::RelaxNG::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::RelaxNG::new |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Schema::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Schema::new |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Text::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Text::attributes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Text::deleteDataString |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Text::replaceDataRegEx |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::Text::replaceDataString |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathExpression::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_SAXParser::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_SAXParser::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_SAXParser::error |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_SAXParser::fatal_error |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_SAXParser::warning |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::__proxy_registry |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::__read |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::__write |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_auto_expand |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_html_options |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::_parser_options |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::base_uri |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::callbacks |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::clean_namespaces |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::complete_attributes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::createDocument |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::expand_entities |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::expand_xinclude |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::finish_push |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::gdome_dom |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::init_push |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::input_callbacks |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::keep_blanks |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::line_numbers |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::load_ext_dtd |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::no_network |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_balanced_chunk |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_chunk |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_fh |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_html_fh |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_html_file |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_html_string |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_string |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::parse_xml_chunk |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::pedantic_parser |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::processXIncludes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::process_xincludes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::push |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::recover |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::recover_silently |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::validation |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | # $Id: LibXML.pm 760 2008-11-11 19:30:27Z pajas $ | |||
| 2 | ||||
| 3 | package XML::LibXML; | |||
| 4 | ||||
| 5 | 3 | 39µs | 13µs | use strict; # spent 9µs making 1 call to strict::import |
| 6 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS # spent 121µs making 1 call to vars::import | |||
| 7 | $skipDTD $skipXMLDeclaration $setTagCompression | |||
| 8 | $MatchCB $ReadCB $OpenCB $CloseCB | |||
| 9 | 3 | 29µs | 10µs | ); |
| 10 | 3 | 36µs | 12µs | use Carp; # spent 60µs making 1 call to Exporter::import |
| 11 | ||||
| 12 | 3 | 141µs | 47µs | use XML::LibXML::Common qw(:encoding :libxml); # spent 308µs making 1 call to Exporter::import |
| 13 | ||||
| 14 | 3 | 32µs | 11µs | use constant XML_XMLNS_NS => 'http://www.w3.org/2000/xmlns/'; # spent 40µs making 1 call to constant::import |
| 15 | 3 | 40µs | 13µs | use constant XML_XML_NS => 'http://www.w3.org/XML/1998/namespace'; # spent 33µs making 1 call to constant::import |
| 16 | ||||
| 17 | 3 | 110µs | 37µs | use XML::LibXML::Error; # spent 9µs making 1 call to UNIVERSAL::import |
| 18 | 3 | 98µs | 33µs | use XML::LibXML::NodeList; # spent 7µs making 1 call to UNIVERSAL::import |
| 19 | 3 | 102µs | 34µs | use XML::LibXML::XPathContext; # spent 7µs making 1 call to UNIVERSAL::import |
| 20 | 3 | 68µs | 23µs | use IO::Handle; # for FH reads called as methods # spent 32µs making 1 call to Exporter::import |
| 21 | ||||
| 22 | BEGIN { | |||
| 23 | ||||
| 24 | 16 | 75µs | 5µs | $VERSION = "1.69"; # VERSION TEMPLATE: DO NOT CHANGE |
| 25 | require Exporter; | |||
| 26 | require DynaLoader; | |||
| 27 | @ISA = qw(DynaLoader Exporter); | |||
| 28 | ||||
| 29 | 3 | 198µs | 66µs | use vars qw($__PROXY_NODE_REGISTRY $__threads_shared $__PROXY_NODE_REGISTRY_MUTEX $__loaded); # spent 66µs making 1 call to vars::import |
| 30 | ||||
| 31 | #-------------------------------------------------------------------------# | |||
| 32 | # export information # | |||
| 33 | #-------------------------------------------------------------------------# | |||
| 34 | %EXPORT_TAGS = ( | |||
| 35 | all => [qw( | |||
| 36 | XML_ELEMENT_NODE | |||
| 37 | XML_ATTRIBUTE_NODE | |||
| 38 | XML_TEXT_NODE | |||
| 39 | XML_CDATA_SECTION_NODE | |||
| 40 | XML_ENTITY_REF_NODE | |||
| 41 | XML_ENTITY_NODE | |||
| 42 | XML_PI_NODE | |||
| 43 | XML_COMMENT_NODE | |||
| 44 | XML_DOCUMENT_NODE | |||
| 45 | XML_DOCUMENT_TYPE_NODE | |||
| 46 | XML_DOCUMENT_FRAG_NODE | |||
| 47 | XML_NOTATION_NODE | |||
| 48 | XML_HTML_DOCUMENT_NODE | |||
| 49 | XML_DTD_NODE | |||
| 50 | XML_ELEMENT_DECL | |||
| 51 | XML_ATTRIBUTE_DECL | |||
| 52 | XML_ENTITY_DECL | |||
| 53 | XML_NAMESPACE_DECL | |||
| 54 | XML_XINCLUDE_END | |||
| 55 | XML_XINCLUDE_START | |||
| 56 | encodeToUTF8 | |||
| 57 | decodeFromUTF8 | |||
| 58 | XML_XMLNS_NS | |||
| 59 | XML_XML_NS | |||
| 60 | )], | |||
| 61 | libxml => [qw( | |||
| 62 | XML_ELEMENT_NODE | |||
| 63 | XML_ATTRIBUTE_NODE | |||
| 64 | XML_TEXT_NODE | |||
| 65 | XML_CDATA_SECTION_NODE | |||
| 66 | XML_ENTITY_REF_NODE | |||
| 67 | XML_ENTITY_NODE | |||
| 68 | XML_PI_NODE | |||
| 69 | XML_COMMENT_NODE | |||
| 70 | XML_DOCUMENT_NODE | |||
| 71 | XML_DOCUMENT_TYPE_NODE | |||
| 72 | XML_DOCUMENT_FRAG_NODE | |||
| 73 | XML_NOTATION_NODE | |||
| 74 | XML_HTML_DOCUMENT_NODE | |||
| 75 | XML_DTD_NODE | |||
| 76 | XML_ELEMENT_DECL | |||
| 77 | XML_ATTRIBUTE_DECL | |||
| 78 | XML_ENTITY_DECL | |||
| 79 | XML_NAMESPACE_DECL | |||
| 80 | XML_XINCLUDE_END | |||
| 81 | XML_XINCLUDE_START | |||
| 82 | )], | |||
| 83 | encoding => [qw( | |||
| 84 | encodeToUTF8 | |||
| 85 | decodeFromUTF8 | |||
| 86 | )], | |||
| 87 | ns => [qw( | |||
| 88 | XML_XMLNS_NS | |||
| 89 | XML_XML_NS | |||
| 90 | )], | |||
| 91 | ); | |||
| 92 | ||||
| 93 | @EXPORT_OK = ( | |||
| 94 | @{$EXPORT_TAGS{all}}, | |||
| 95 | ); | |||
| 96 | ||||
| 97 | @EXPORT = ( | |||
| 98 | @{$EXPORT_TAGS{all}}, | |||
| 99 | ); | |||
| 100 | ||||
| 101 | #-------------------------------------------------------------------------# | |||
| 102 | # initialization of the global variables # | |||
| 103 | #-------------------------------------------------------------------------# | |||
| 104 | $skipDTD = 0; | |||
| 105 | $skipXMLDeclaration = 0; | |||
| 106 | $setTagCompression = 0; | |||
| 107 | ||||
| 108 | $MatchCB = undef; | |||
| 109 | $ReadCB = undef; | |||
| 110 | $OpenCB = undef; | |||
| 111 | $CloseCB = undef; | |||
| 112 | ||||
| 113 | # if ($threads::threads) { | |||
| 114 | # our $__THREADS_TID = 0; | |||
| 115 | # eval q{ | |||
| 116 | # use threads::shared; | |||
| 117 | # our $__PROXY_NODE_REGISTRY_MUTEX :shared = 0; | |||
| 118 | # }; | |||
| 119 | # die $@ if $@; | |||
| 120 | # } | |||
| 121 | #-------------------------------------------------------------------------# | |||
| 122 | # bootstrapping # | |||
| 123 | #-------------------------------------------------------------------------# | |||
| 124 | bootstrap XML::LibXML $VERSION; # spent 1.48ms making 1 call to DynaLoader::bootstrap | |||
| 125 | undef &AUTOLOAD; | |||
| 126 | ||||
| 127 | 1 | 5.05ms | 5.05ms | } # BEGIN |
| 128 | ||||
| 129 | # spent 2.15ms (1.89+257µs) within XML::LibXML::import which was called 5 times, avg 430µs/call:
# once (1.28ms+115µs) at line 1177
# once (181µs+36µs) at line 297 of /usr/lib/perl5/XML/LibXSLT.pm
# once (150µs+34µs) at line 30 of /home/chris/git/koha.git/C4/XSLT.pm
# once (145µs+36µs) at line 10 of /usr/local/lib/perl/5.10.0/XML/LibXML/SAX.pm
# once (131µs+35µs) at line 7 of /usr/lib/perl5/XML/LibXSLT.pm | |||
| 130 | 19 | 63µs | 3µs | my $package=shift; |
| 131 | if (grep /^:threads_shared$/, @_) { | |||
| 132 | require threads; | |||
| 133 | if (!defined($__threads_shared)) { | |||
| 134 | if (INIT_THREAD_SUPPORT()) { | |||
| 135 | eval q{ | |||
| 136 | use threads::shared; | |||
| 137 | share($__PROXY_NODE_REGISTRY_MUTEX); | |||
| 138 | }; | |||
| 139 | if ($@) { # something went wrong | |||
| 140 | DISABLE_THREAD_SUPPORT(); # leave the library in a usable state | |||
| 141 | die $@; # and die | |||
| 142 | } | |||
| 143 | $__PROXY_NODE_REGISTRY = XML::LibXML::HashTable->new(); | |||
| 144 | $__threads_shared=1; | |||
| 145 | } else { | |||
| 146 | croak("XML::LibXML or Perl compiled without ithread support!"); | |||
| 147 | } | |||
| 148 | } elsif (!$__threads_shared) { | |||
| 149 | croak("XML::LibXML already loaded without thread support. Too late to enable thread support!"); | |||
| 150 | } | |||
| 151 | } elsif (defined $XML::LibXML::__loaded) { | |||
| 152 | $__threads_shared=0 if not defined $__threads_shared; | |||
| 153 | } | |||
| 154 | __PACKAGE__->export_to_level(1,$package,grep !/^:threads(_shared)?$/,@_); # spent 114µs making 5 calls to Exporter::export_to_level, avg 23µs/call | |||
| 155 | } | |||
| 156 | ||||
| 157 | # spent 8µs within XML::LibXML::threads_shared_enabled which was called
# once (8µs+0s) at line 28 of /usr/lib/perl5/XML/LibXSLT.pm | |||
| 158 | 1 | 2µs | 2µs | return $__threads_shared ? 1 : 0; |
| 159 | } | |||
| 160 | ||||
| 161 | # if ($threads::threads) { | |||
| 162 | # our $__PROXY_NODE_REGISTRY = XML::LibXML::HashTable->new(); | |||
| 163 | # } | |||
| 164 | ||||
| 165 | #-------------------------------------------------------------------------# | |||
| 166 | # test exact version (up to patch-level) # | |||
| 167 | #-------------------------------------------------------------------------# | |||
| 168 | { | |||
| 169 | 2 | 40µs | 20µs | my ($runtime_version) = LIBXML_RUNTIME_VERSION() =~ /^(\d+)/; # spent 34µs making 1 call to XML::LibXML::LIBXML_RUNTIME_VERSION |
| 170 | 1 | 15µs | 15µs | if ( $runtime_version < LIBXML_VERSION ) { # spent 12µs making 1 call to XML::LibXML::LIBXML_VERSION |
| 171 | warn "Warning: XML::LibXML compiled against libxml2 ".LIBXML_VERSION. | |||
| 172 | ", but runtime libxml2 is older $runtime_version\n"; | |||
| 173 | } | |||
| 174 | } | |||
| 175 | ||||
| 176 | #-------------------------------------------------------------------------# | |||
| 177 | # parser constructor # | |||
| 178 | #-------------------------------------------------------------------------# | |||
| 179 | # spent 26µs within XML::LibXML::new which was called
# once (26µs+0s) by XML::LibXML::SAX::_parse_systemid at line 50 of /usr/local/lib/perl/5.10.0/XML/LibXML/SAX.pm | |||
| 180 | 9 | 21µs | 2µs | my $class = shift; |
| 181 | my %options = @_; | |||
| 182 | if ( not exists $options{XML_LIBXML_KEEP_BLANKS} ) { | |||
| 183 | $options{XML_LIBXML_KEEP_BLANKS} = 1; | |||
| 184 | } | |||
| 185 | ||||
| 186 | if ( defined $options{catalog} ) { | |||
| 187 | $class->load_catalog( $options{catalog} ); | |||
| 188 | delete $options{catalog}; | |||
| 189 | } | |||
| 190 | ||||
| 191 | my $self = bless \%options, $class; | |||
| 192 | if ( defined $options{Handler} ) { | |||
| 193 | $self->set_handler( $options{Handler} ); | |||
| 194 | } | |||
| 195 | ||||
| 196 | $self->{XML_LIBXML_EXT_DTD} = 1; | |||
| 197 | $self->{_State_} = 0; | |||
| 198 | return $self; | |||
| 199 | } | |||
| 200 | ||||
| 201 | #-------------------------------------------------------------------------# | |||
| 202 | # Threads support methods # | |||
| 203 | #-------------------------------------------------------------------------# | |||
| 204 | ||||
| 205 | # threads doc says CLONE's API may change in future, which would break | |||
| 206 | # an XS method prototype | |||
| 207 | sub CLONE { | |||
| 208 | if ($XML::LibXML::__threads_shared) { | |||
| 209 | XML::LibXML::_CLONE( $_[0] ); | |||
| 210 | } | |||
| 211 | } | |||
| 212 | ||||
| 213 | sub CLONE_SKIP { | |||
| 214 | return $XML::LibXML::__threads_shared ? 0 : 1; | |||
| 215 | } | |||
| 216 | ||||
| 217 | sub __proxy_registry { | |||
| 218 | my ($class)=caller; | |||
| 219 | die "This version of $class uses API of XML::LibXML 1.66 which is not compatible with XML::LibXML $VERSION. Please upgrade $class!\n"; | |||
| 220 | } | |||
| 221 | ||||
| 222 | #-------------------------------------------------------------------------# | |||
| 223 | # DOM Level 2 document constructor # | |||
| 224 | #-------------------------------------------------------------------------# | |||
| 225 | ||||
| 226 | sub createDocument { | |||
| 227 | my $self = shift; | |||
| 228 | if (!@_ or $_[0] =~ m/^\d\.\d$/) { | |||
| 229 | # for backward compatibility | |||
| 230 | return XML::LibXML::Document->new(@_); | |||
| 231 | } | |||
| 232 | else { | |||
| 233 | # DOM API: createDocument(namespaceURI, qualifiedName, doctype?) | |||
| 234 | my $doc = XML::LibXML::Document-> new; | |||
| 235 | my $el = $doc->createElementNS(shift, shift); | |||
| 236 | $doc->setDocumentElement($el); | |||
| 237 | $doc->setExternalSubset(shift) if @_; | |||
| 238 | return $doc; | |||
| 239 | } | |||
| 240 | } | |||
| 241 | ||||
| 242 | #-------------------------------------------------------------------------# | |||
| 243 | # callback functions # | |||
| 244 | #-------------------------------------------------------------------------# | |||
| 245 | ||||
| 246 | sub input_callbacks { | |||
| 247 | my $self = shift; | |||
| 248 | my $icbclass = shift; | |||
| 249 | ||||
| 250 | if ( defined $icbclass ) { | |||
| 251 | $self->{XML_LIBXML_CALLBACK_STACK} = $icbclass; | |||
| 252 | } | |||
| 253 | return $self->{XML_LIBXML_CALLBACK_STACK}; | |||
| 254 | } | |||
| 255 | ||||
| 256 | sub match_callback { | |||
| 257 | 8 | 8µs | 1µs | my $self = shift; |
| 258 | if ( ref $self ) { | |||
| 259 | if ( scalar @_ ) { | |||
| 260 | $self->{XML_LIBXML_MATCH_CB} = shift; | |||
| 261 | $self->{XML_LIBXML_CALLBACK_STACK} = undef; | |||
| 262 | } | |||
| 263 | return $self->{XML_LIBXML_MATCH_CB}; | |||
| 264 | } | |||
| 265 | else { | |||
| 266 | $MatchCB = shift if scalar @_; | |||
| 267 | return $MatchCB; | |||
| 268 | } | |||
| 269 | } | |||
| 270 | ||||
| 271 | # spent 8µs within XML::LibXML::read_callback which was called
# once (8µs+0s) by XML::LibXML::_init_callbacks at line 479 | |||
| 272 | 4 | 4µs | 900ns | my $self = shift; |
| 273 | if ( ref $self ) { | |||
| 274 | if ( scalar @_ ) { | |||
| 275 | $self->{XML_LIBXML_READ_CB} = shift; | |||
| 276 | $self->{XML_LIBXML_CALLBACK_STACK} = undef; | |||
| 277 | } | |||
| 278 | return $self->{XML_LIBXML_READ_CB}; | |||
| 279 | } | |||
| 280 | else { | |||
| 281 | $ReadCB = shift if scalar @_; | |||
| 282 | return $ReadCB; | |||
| 283 | } | |||
| 284 | } | |||
| 285 | ||||
| 286 | # spent 8µs within XML::LibXML::close_callback which was called
# once (8µs+0s) by XML::LibXML::_init_callbacks at line 480 | |||
| 287 | 4 | 3µs | 825ns | my $self = shift; |
| 288 | if ( ref $self ) { | |||
| 289 | if ( scalar @_ ) { | |||
| 290 | $self->{XML_LIBXML_CLOSE_CB} = shift; | |||
| 291 | $self->{XML_LIBXML_CALLBACK_STACK} = undef; | |||
| 292 | } | |||
| 293 | return $self->{XML_LIBXML_CLOSE_CB}; | |||
| 294 | } | |||
| 295 | else { | |||
| 296 | $CloseCB = shift if scalar @_; | |||
| 297 | return $CloseCB; | |||
| 298 | } | |||
| 299 | } | |||
| 300 | ||||
| 301 | # spent 9µs within XML::LibXML::open_callback which was called
# once (9µs+0s) by XML::LibXML::_init_callbacks at line 478 | |||
| 302 | 4 | 4µs | 925ns | my $self = shift; |
| 303 | if ( ref $self ) { | |||
| 304 | if ( scalar @_ ) { | |||
| 305 | $self->{XML_LIBXML_OPEN_CB} = shift; | |||
| 306 | $self->{XML_LIBXML_CALLBACK_STACK} = undef; | |||
| 307 | } | |||
| 308 | return $self->{XML_LIBXML_OPEN_CB}; | |||
| 309 | } | |||
| 310 | else { | |||
| 311 | $OpenCB = shift if scalar @_; | |||
| 312 | return $OpenCB; | |||
| 313 | } | |||
| 314 | } | |||
| 315 | ||||
| 316 | sub callbacks { | |||
| 317 | my $self = shift; | |||
| 318 | if ( ref $self ) { | |||
| 319 | if (@_) { | |||
| 320 | my ($match, $open, $read, $close) = @_; | |||
| 321 | @{$self}{qw(XML_LIBXML_MATCH_CB XML_LIBXML_OPEN_CB XML_LIBXML_READ_CB XML_LIBXML_CLOSE_CB)} = ($match, $open, $read, $close); | |||
| 322 | $self->{XML_LIBXML_CALLBACK_STACK} = undef; | |||
| 323 | } | |||
| 324 | else { | |||
| 325 | return @{$self}{qw(XML_LIBXML_MATCH_CB XML_LIBXML_OPEN_CB XML_LIBXML_READ_CB XML_LIBXML_CLOSE_CB)}; | |||
| 326 | } | |||
| 327 | } | |||
| 328 | else { | |||
| 329 | if (@_) { | |||
| 330 | ( $MatchCB, $OpenCB, $ReadCB, $CloseCB ) = @_; | |||
| 331 | } | |||
| 332 | else { | |||
| 333 | return ( $MatchCB, $OpenCB, $ReadCB, $CloseCB ); | |||
| 334 | } | |||
| 335 | } | |||
| 336 | } | |||
| 337 | ||||
| 338 | #-------------------------------------------------------------------------# | |||
| 339 | # member variable manipulation # | |||
| 340 | #-------------------------------------------------------------------------# | |||
| 341 | sub validation { | |||
| 342 | my $self = shift; | |||
| 343 | $self->{XML_LIBXML_VALIDATION} = shift if scalar @_; | |||
| 344 | return $self->{XML_LIBXML_VALIDATION}; | |||
| 345 | } | |||
| 346 | ||||
| 347 | sub recover { | |||
| 348 | my $self = shift; | |||
| 349 | $self->{XML_LIBXML_RECOVER} = shift if scalar @_; | |||
| 350 | return $self->{XML_LIBXML_RECOVER}; | |||
| 351 | } | |||
| 352 | ||||
| 353 | sub recover_silently { | |||
| 354 | my $self = shift; | |||
| 355 | my $arg = shift; | |||
| 356 | (($arg == 1) ? $self->recover(2) : $self->recover($arg)) if defined($arg); | |||
| 357 | return ($self->recover() == 2) ? 1 : 0; | |||
| 358 | } | |||
| 359 | ||||
| 360 | sub expand_entities { | |||
| 361 | my $self = shift; | |||
| 362 | $self->{XML_LIBXML_EXPAND_ENTITIES} = shift if scalar @_; | |||
| 363 | return $self->{XML_LIBXML_EXPAND_ENTITIES}; | |||
| 364 | } | |||
| 365 | ||||
| 366 | sub keep_blanks { | |||
| 367 | my $self = shift; | |||
| 368 | $self->{XML_LIBXML_KEEP_BLANKS} = shift if scalar @_; | |||
| 369 | return $self->{XML_LIBXML_KEEP_BLANKS}; | |||
| 370 | } | |||
| 371 | ||||
| 372 | sub pedantic_parser { | |||
| 373 | my $self = shift; | |||
| 374 | $self->{XML_LIBXML_PEDANTIC} = shift if scalar @_; | |||
| 375 | return $self->{XML_LIBXML_PEDANTIC}; | |||
| 376 | } | |||
| 377 | ||||
| 378 | sub line_numbers { | |||
| 379 | my $self = shift; | |||
| 380 | $self->{XML_LIBXML_LINENUMBERS} = shift if scalar @_; | |||
| 381 | return $self->{XML_LIBXML_LINENUMBERS}; | |||
| 382 | } | |||
| 383 | ||||
| 384 | sub no_network { | |||
| 385 | my $self = shift; | |||
| 386 | $self->{XML_LIBXML_NONET} = shift if scalar @_; | |||
| 387 | return $self->{XML_LIBXML_NONET}; | |||
| 388 | } | |||
| 389 | ||||
| 390 | sub load_ext_dtd { | |||
| 391 | my $self = shift; | |||
| 392 | $self->{XML_LIBXML_EXT_DTD} = shift if scalar @_; | |||
| 393 | return $self->{XML_LIBXML_EXT_DTD}; | |||
| 394 | } | |||
| 395 | ||||
| 396 | sub complete_attributes { | |||
| 397 | my $self = shift; | |||
| 398 | $self->{XML_LIBXML_COMPLETE_ATTR} = shift if scalar @_; | |||
| 399 | return $self->{XML_LIBXML_COMPLETE_ATTR}; | |||
| 400 | } | |||
| 401 | ||||
| 402 | sub expand_xinclude { | |||
| 403 | my $self = shift; | |||
| 404 | $self->{XML_LIBXML_EXPAND_XINCLUDE} = shift if scalar @_; | |||
| 405 | return $self->{XML_LIBXML_EXPAND_XINCLUDE}; | |||
| 406 | } | |||
| 407 | ||||
| 408 | sub base_uri { | |||
| 409 | my $self = shift; | |||
| 410 | $self->{XML_LIBXML_BASE_URI} = shift if scalar @_; | |||
| 411 | return $self->{XML_LIBXML_BASE_URI}; | |||
| 412 | } | |||
| 413 | ||||
| 414 | sub gdome_dom { | |||
| 415 | my $self = shift; | |||
| 416 | $self->{XML_LIBXML_GDOME} = shift if scalar @_; | |||
| 417 | return $self->{XML_LIBXML_GDOME}; | |||
| 418 | } | |||
| 419 | ||||
| 420 | sub clean_namespaces { | |||
| 421 | my $self = shift; | |||
| 422 | $self->{XML_LIBXML_NSCLEAN} = shift if scalar @_; | |||
| 423 | return $self->{XML_LIBXML_NSCLEAN}; | |||
| 424 | } | |||
| 425 | ||||
| 426 | #-------------------------------------------------------------------------# | |||
| 427 | # set the optional SAX(2) handler # | |||
| 428 | #-------------------------------------------------------------------------# | |||
| 429 | # spent 23µs within XML::LibXML::set_handler which was called 2 times, avg 12µs/call:
# once (12µs+0s) by XML::LibXML::SAX::_parse at line 71 of /usr/local/lib/perl/5.10.0/XML/LibXML/SAX.pm
# once (11µs+0s) by XML::LibXML::SAX::_parse at line 81 of /usr/local/lib/perl/5.10.0/XML/LibXML/SAX.pm | |||
| 430 | 10 | 13µs | 1µs | my $self = shift; |
| 431 | if ( defined $_[0] ) { | |||
| 432 | $self->{HANDLER} = $_[0]; | |||
| 433 | ||||
| 434 | $self->{SAX_ELSTACK} = []; | |||
| 435 | $self->{SAX} = {State => 0}; | |||
| 436 | } | |||
| 437 | else { | |||
| 438 | # undef SAX handling | |||
| 439 | $self->{SAX_ELSTACK} = []; | |||
| 440 | delete $self->{HANDLER}; | |||
| 441 | delete $self->{SAX}; | |||
| 442 | } | |||
| 443 | } | |||
| 444 | ||||
| 445 | #-------------------------------------------------------------------------# | |||
| 446 | # helper functions # | |||
| 447 | #-------------------------------------------------------------------------# | |||
| 448 | sub _auto_expand { | |||
| 449 | my ( $self, $result, $uri ) = @_; | |||
| 450 | ||||
| 451 | $result->setBaseURI( $uri ) if defined $uri; | |||
| 452 | ||||
| 453 | if ( defined $self->{XML_LIBXML_EXPAND_XINCLUDE} | |||
| 454 | and $self->{XML_LIBXML_EXPAND_XINCLUDE} == 1 ) { | |||
| 455 | $self->{_State_} = 1; | |||
| 456 | eval { $self->processXIncludes($result); }; | |||
| 457 | my $err = $@; | |||
| 458 | $self->{_State_} = 0; | |||
| 459 | if ($err) { | |||
| 460 | $self->_cleanup_callbacks(); | |||
| 461 | $result = undef; | |||
| 462 | croak $err; | |||
| 463 | } | |||
| 464 | } | |||
| 465 | return $result; | |||
| 466 | } | |||
| 467 | ||||
| 468 | # spent 117µs (25+92) within XML::LibXML::_init_callbacks which was called
# once (25µs+92µs) by XML::LibXML::parse_file at line 631 | |||
| 469 | 11 | 52µs | 5µs | my $self = shift; |
| 470 | my $icb = $self->{XML_LIBXML_CALLBACK_STACK}; | |||
| 471 | ||||
| 472 | unless ( defined $icb ) { | |||
| 473 | $self->{XML_LIBXML_CALLBACK_STACK} = XML::LibXML::InputCallback->new(); # spent 15µs making 1 call to XML::LibXML::InputCallback::new | |||
| 474 | $icb = $self->{XML_LIBXML_CALLBACK_STACK}; | |||
| 475 | } | |||
| 476 | ||||
| 477 | my $mcb = $self->match_callback(); # spent 10µs making 1 call to XML::LibXML::match_callback | |||
| 478 | my $ocb = $self->open_callback(); # spent 9µs making 1 call to XML::LibXML::open_callback | |||
| 479 | my $rcb = $self->read_callback(); # spent 8µs making 1 call to XML::LibXML::read_callback | |||
| 480 | my $ccb = $self->close_callback(); # spent 8µs making 1 call to XML::LibXML::close_callback | |||
| 481 | ||||
| 482 | if ( defined $mcb and defined $ocb and defined $rcb and defined $ccb ) { | |||
| 483 | $icb->register_callbacks( [$mcb, $ocb, $rcb, $ccb] ); | |||
| 484 | } | |||
| 485 | ||||
| 486 | $icb->init_callbacks(); # spent 40µs making 1 call to XML::LibXML::InputCallback::init_callbacks | |||
| 487 | } | |||
| 488 | ||||
| 489 | # spent 56µs (13+43) within XML::LibXML::_cleanup_callbacks which was called
# once (13µs+43µs) by XML::LibXML::parse_file at line 656 | |||
| 490 | 4 | 23µs | 6µs | my $self = shift; |
| 491 | $self->{XML_LIBXML_CALLBACK_STACK}->cleanup_callbacks(); # spent 22µs making 1 call to XML::LibXML::InputCallback::cleanup_callbacks | |||
| 492 | my $mcb = $self->match_callback(); # spent 8µs making 1 call to XML::LibXML::match_callback | |||
| 493 | $self->{XML_LIBXML_CALLBACK_STACK}->unregister_callbacks( [$mcb] ); # spent 12µs making 1 call to XML::LibXML::InputCallback::unregister_callbacks | |||
| 494 | } | |||
| 495 | ||||
| 496 | sub __read { | |||
| 497 | read($_[0], $_[1], $_[2]); | |||
| 498 | } | |||
| 499 | ||||
| 500 | sub __write { | |||
| 501 | if ( ref( $_[0] ) ) { | |||
| 502 | $_[0]->write( $_[1], $_[2] ); | |||
| 503 | } | |||
| 504 | else { | |||
| 505 | $_[0]->write( $_[1] ); | |||
| 506 | } | |||
| 507 | } | |||
| 508 | ||||
| 509 | # currently this is only used in the XInlcude processor | |||
| 510 | # but in the future, all parsing functions should turn to | |||
| 511 | # the new libxml2 parsing API internally and this will | |||
| 512 | # become handy | |||
| 513 | sub _parser_options { | |||
| 514 | my ($self,$opts)=@_; | |||
| 515 | $opts = {} unless ref $opts; | |||
| 516 | my $flags = 0; | |||
| 517 | $flags |= 1 if exists $opts->{recover} ? $opts->{recover} : $self->recover; | |||
| 518 | $flags |= 2 if exists $opts->{expand_entities} ? $opts->{expand_entities} : $self->expand_entities; | |||
| 519 | $flags |= 4 if exists $opts->{load_ext_dtd} ? $opts->{load_ext_dtd} : $self->load_ext_dtd; | |||
| 520 | $flags |= 8 if exists $opts->{complete_attributes} ? $opts->{complete_attributes} : $self->complete_attributes; | |||
| 521 | $flags |= 16 if exists $opts->{validation} ? $opts->{validation} : $self->validation; | |||
| 522 | $flags |= 32 if $opts->{suppress_errors}; | |||
| 523 | $flags |= 64 if $opts->{suppress_warnings}; | |||
| 524 | $flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser; | |||
| 525 | $flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks(); | |||
| 526 | $flags |= 1024 if exists $opts->{expand_xinclude} ? $opts->{expand_xinclude} : $self->expand_xinclude; | |||
| 527 | $flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : $self->no_network; | |||
| 528 | $flags |= 8192 if exists $opts->{clean_namespaces} ? $opts->{clean_namespaces} : $self->clean_namespaces; | |||
| 529 | $flags |= 16384 if $opts->{no_cdata}; | |||
| 530 | $flags |= 32768 if $opts->{no_xinclude_nodes}; | |||
| 531 | return ($flags); | |||
| 532 | } | |||
| 533 | ||||
| 534 | ||||
| 535 | #-------------------------------------------------------------------------# | |||
| 536 | # parsing functions # | |||
| 537 | #-------------------------------------------------------------------------# | |||
| 538 | # all parsing functions handle normal as SAX parsing at the same time. | |||
| 539 | # note that SAX parsing is handled incomplete! use XML::LibXML::SAX for | |||
| 540 | # complete parsing sequences | |||
| 541 | #-------------------------------------------------------------------------# | |||
| 542 | sub parse_string { | |||
| 543 | my $self = shift; | |||
| 544 | croak("parse_string is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 545 | croak("parse already in progress") if $self->{_State_}; | |||
| 546 | ||||
| 547 | unless ( defined $_[0] and length $_[0] ) { | |||
| 548 | croak("Empty String"); | |||
| 549 | } | |||
| 550 | ||||
| 551 | $self->{_State_} = 1; | |||
| 552 | my $result; | |||
| 553 | ||||
| 554 | $self->_init_callbacks(); | |||
| 555 | ||||
| 556 | if ( defined $self->{SAX} ) { | |||
| 557 | my $string = shift; | |||
| 558 | $self->{SAX_ELSTACK} = []; | |||
| 559 | eval { $result = $self->_parse_sax_string($string); }; | |||
| 560 | my $err = $@; | |||
| 561 | $self->{_State_} = 0; | |||
| 562 | if ($err) { | |||
| 563 | chomp $err unless ref $err; | |||
| 564 | $self->_cleanup_callbacks(); | |||
| 565 | croak $err; | |||
| 566 | } | |||
| 567 | } | |||
| 568 | else { | |||
| 569 | eval { $result = $self->_parse_string( @_ ); }; | |||
| 570 | ||||
| 571 | my $err = $@; | |||
| 572 | $self->{_State_} = 0; | |||
| 573 | if ($err) { | |||
| 574 | chomp $err unless ref $err; | |||
| 575 | $self->_cleanup_callbacks(); | |||
| 576 | croak $err; | |||
| 577 | } | |||
| 578 | ||||
| 579 | $result = $self->_auto_expand( $result, $self->{XML_LIBXML_BASE_URI} ); | |||
| 580 | } | |||
| 581 | $self->_cleanup_callbacks(); | |||
| 582 | ||||
| 583 | return $result; | |||
| 584 | } | |||
| 585 | ||||
| 586 | sub parse_fh { | |||
| 587 | my $self = shift; | |||
| 588 | croak("parse_fh is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 589 | croak("parse already in progress") if $self->{_State_}; | |||
| 590 | $self->{_State_} = 1; | |||
| 591 | my $result; | |||
| 592 | ||||
| 593 | $self->_init_callbacks(); | |||
| 594 | ||||
| 595 | if ( defined $self->{SAX} ) { | |||
| 596 | $self->{SAX_ELSTACK} = []; | |||
| 597 | eval { $self->_parse_sax_fh( @_ ); }; | |||
| 598 | my $err = $@; | |||
| 599 | $self->{_State_} = 0; | |||
| 600 | if ($err) { | |||
| 601 | chomp $err unless ref $err; | |||
| 602 | $self->_cleanup_callbacks(); | |||
| 603 | croak $err; | |||
| 604 | } | |||
| 605 | } | |||
| 606 | else { | |||
| 607 | eval { $result = $self->_parse_fh( @_ ); }; | |||
| 608 | my $err = $@; | |||
| 609 | $self->{_State_} = 0; | |||
| 610 | if ($err) { | |||
| 611 | chomp $err unless ref $err; | |||
| 612 | $self->_cleanup_callbacks(); | |||
| 613 | croak $err; | |||
| 614 | } | |||
| 615 | ||||
| 616 | $result = $self->_auto_expand( $result, $self->{XML_LIBXML_BASE_URI} ); | |||
| 617 | } | |||
| 618 | ||||
| 619 | $self->_cleanup_callbacks(); | |||
| 620 | ||||
| 621 | return $result; | |||
| 622 | } | |||
| 623 | ||||
| 624 | # spent 12.7ms (21µs+12.6) within XML::LibXML::parse_file which was called
# once (21µs+12.6ms) by XML::LibXML::SAX::_parse at line 73 of /usr/local/lib/perl/5.10.0/XML/LibXML/SAX.pm | |||
| 625 | 15 | 112µs | 7µs | my $self = shift; |
| 626 | croak("parse_file is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 627 | croak("parse already in progress") if $self->{_State_}; | |||
| 628 | $self->{_State_} = 1; | |||
| 629 | my $result; | |||
| 630 | ||||
| 631 | $self->_init_callbacks(); # spent 117µs making 1 call to XML::LibXML::_init_callbacks | |||
| 632 | ||||
| 633 | if ( defined $self->{SAX} ) { | |||
| 634 | $self->{SAX_ELSTACK} = []; | |||
| 635 | 1 | 5.45ms | 5.45ms | eval { $self->_parse_sax_file( @_ ); }; # spent 12.5ms making 1 call to XML::LibXML::_parse_sax_file
# spent 3.66ms making 209 calls to XML::SAX::Base::characters, avg 18µs/call
# spent 2.66ms making 109 calls to XML::SAX::Base::start_element, avg 24µs/call
# spent 1.52ms making 109 calls to XML::SAX::Base::end_element, avg 14µs/call
# spent 200µs making 18 calls to XML::SAX::Base::comment, avg 11µs/call
# spent 80µs making 5 calls to XML::SAX::Base::end_prefix_mapping, avg 16µs/call
# spent 79µs making 5 calls to XML::SAX::Base::start_prefix_mapping, avg 16µs/call
# spent 50µs making 1 call to XML::SAX::Base::start_document
# spent 32µs making 1 call to XML::SAX::Base::xml_decl |
| 636 | my $err = $@; | |||
| 637 | $self->{_State_} = 0; | |||
| 638 | if ($err) { | |||
| 639 | chomp $err unless ref $err; | |||
| 640 | $self->_cleanup_callbacks(); | |||
| 641 | croak $err; | |||
| 642 | } | |||
| 643 | } | |||
| 644 | else { | |||
| 645 | eval { $result = $self->_parse_file(@_); }; | |||
| 646 | my $err = $@; | |||
| 647 | $self->{_State_} = 0; | |||
| 648 | if ($err) { | |||
| 649 | chomp $err unless ref $err; | |||
| 650 | $self->_cleanup_callbacks(); | |||
| 651 | croak $err; | |||
| 652 | } | |||
| 653 | ||||
| 654 | $result = $self->_auto_expand( $result ); | |||
| 655 | } | |||
| 656 | $self->_cleanup_callbacks(); # spent 56µs making 1 call to XML::LibXML::_cleanup_callbacks | |||
| 657 | ||||
| 658 | return $result; | |||
| 659 | } | |||
| 660 | ||||
| 661 | sub parse_xml_chunk { | |||
| 662 | my $self = shift; | |||
| 663 | # max 2 parameter: | |||
| 664 | # 1: the chunk | |||
| 665 | # 2: the encoding of the string | |||
| 666 | croak("parse_xml_chunk is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 667 | croak("parse already in progress") if $self->{_State_}; my $result; | |||
| 668 | ||||
| 669 | unless ( defined $_[0] and length $_[0] ) { | |||
| 670 | croak("Empty String"); | |||
| 671 | } | |||
| 672 | ||||
| 673 | $self->{_State_} = 1; | |||
| 674 | ||||
| 675 | $self->_init_callbacks(); | |||
| 676 | ||||
| 677 | if ( defined $self->{SAX} ) { | |||
| 678 | eval { | |||
| 679 | $self->_parse_sax_xml_chunk( @_ ); | |||
| 680 | ||||
| 681 | # this is required for XML::GenericChunk. | |||
| 682 | # in normal case is_filter is not defined, an thus the parsing | |||
| 683 | # will be terminated. in case of a SAX filter the parsing is not | |||
| 684 | # finished at that state. therefore we must not reset the parsing | |||
| 685 | unless ( $self->{IS_FILTER} ) { | |||
| 686 | $result = $self->{HANDLER}->end_document(); | |||
| 687 | } | |||
| 688 | }; | |||
| 689 | } | |||
| 690 | else { | |||
| 691 | eval { $result = $self->_parse_xml_chunk( @_ ); }; | |||
| 692 | } | |||
| 693 | ||||
| 694 | $self->_cleanup_callbacks(); | |||
| 695 | ||||
| 696 | my $err = $@; | |||
| 697 | $self->{_State_} = 0; | |||
| 698 | if ($err) { | |||
| 699 | chomp $err unless ref $err; | |||
| 700 | croak $err; | |||
| 701 | } | |||
| 702 | ||||
| 703 | return $result; | |||
| 704 | } | |||
| 705 | ||||
| 706 | sub parse_balanced_chunk { | |||
| 707 | my $self = shift; | |||
| 708 | $self->_init_callbacks(); | |||
| 709 | my $rv; | |||
| 710 | eval { | |||
| 711 | $rv = $self->parse_xml_chunk( @_ ); | |||
| 712 | }; | |||
| 713 | my $err = $@; | |||
| 714 | $self->_cleanup_callbacks(); | |||
| 715 | if ( $err ) { | |||
| 716 | chomp $err unless ref $err; | |||
| 717 | croak $err; | |||
| 718 | } | |||
| 719 | return $rv | |||
| 720 | } | |||
| 721 | ||||
| 722 | # java style | |||
| 723 | sub processXIncludes { | |||
| 724 | my $self = shift; | |||
| 725 | my $doc = shift; | |||
| 726 | my $opts = shift; | |||
| 727 | my $options = $self->_parser_options($opts); | |||
| 728 | if ( $self->{_State_} != 1 ) { | |||
| 729 | $self->_init_callbacks(); | |||
| 730 | } | |||
| 731 | my $rv; | |||
| 732 | eval { | |||
| 733 | $rv = $self->_processXIncludes($doc || " ", $options); | |||
| 734 | }; | |||
| 735 | my $err = $@; | |||
| 736 | if ( $self->{_State_} != 1 ) { | |||
| 737 | $self->_cleanup_callbacks(); | |||
| 738 | } | |||
| 739 | ||||
| 740 | if ( $err ) { | |||
| 741 | chomp $err unless ref $err; | |||
| 742 | croak $err; | |||
| 743 | } | |||
| 744 | return $rv; | |||
| 745 | } | |||
| 746 | ||||
| 747 | # perl style | |||
| 748 | sub process_xincludes { | |||
| 749 | my $self = shift; | |||
| 750 | my $doc = shift; | |||
| 751 | my $opts = shift; | |||
| 752 | my $options = $self->_parser_options($opts); | |||
| 753 | ||||
| 754 | my $rv; | |||
| 755 | $self->_init_callbacks(); | |||
| 756 | eval { | |||
| 757 | $rv = $self->_processXIncludes($doc || " ", $options); | |||
| 758 | }; | |||
| 759 | my $err = $@; | |||
| 760 | $self->_cleanup_callbacks(); | |||
| 761 | if ( $err ) { | |||
| 762 | chomp $err unless ref $err; | |||
| 763 | croak $@; | |||
| 764 | } | |||
| 765 | return $rv; | |||
| 766 | } | |||
| 767 | ||||
| 768 | #-------------------------------------------------------------------------# | |||
| 769 | # HTML parsing functions # | |||
| 770 | #-------------------------------------------------------------------------# | |||
| 771 | ||||
| 772 | sub _html_options { | |||
| 773 | my ($self,$opts)=@_; | |||
| 774 | $opts = {} unless ref $opts; | |||
| 775 | # return (undef,undef) unless ref $opts; | |||
| 776 | my $flags = 0; | |||
| 777 | $flags |= 1 if exists $opts->{recover} ? $opts->{recover} : $self->recover; | |||
| 778 | $flags |= 32 if $opts->{suppress_errors}; | |||
| 779 | $flags |= 64 if $opts->{suppress_warnings}; | |||
| 780 | $flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser; | |||
| 781 | $flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks; | |||
| 782 | $flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : !$self->no_network; | |||
| 783 | return ($opts->{URI},$opts->{encoding},$flags); | |||
| 784 | } | |||
| 785 | ||||
| 786 | sub parse_html_string { | |||
| 787 | my ($self,$str,$opts) = @_; | |||
| 788 | croak("parse_html_string is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 789 | croak("parse already in progress") if $self->{_State_}; | |||
| 790 | ||||
| 791 | unless ( defined $str and length $str ) { | |||
| 792 | croak("Empty String"); | |||
| 793 | } | |||
| 794 | $self->{_State_} = 1; | |||
| 795 | my $result; | |||
| 796 | ||||
| 797 | $self->_init_callbacks(); | |||
| 798 | eval { | |||
| 799 | $result = $self->_parse_html_string( $str, | |||
| 800 | $self->_html_options($opts) | |||
| 801 | ); | |||
| 802 | }; | |||
| 803 | my $err = $@; | |||
| 804 | $self->{_State_} = 0; | |||
| 805 | if ($err) { | |||
| 806 | chomp $err unless ref $err; | |||
| 807 | $self->_cleanup_callbacks(); | |||
| 808 | croak $err; | |||
| 809 | } | |||
| 810 | ||||
| 811 | $self->_cleanup_callbacks(); | |||
| 812 | ||||
| 813 | return $result; | |||
| 814 | } | |||
| 815 | ||||
| 816 | sub parse_html_file { | |||
| 817 | my ($self,$file,$opts) = @_; | |||
| 818 | croak("parse_html_file is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 819 | croak("parse already in progress") if $self->{_State_}; | |||
| 820 | $self->{_State_} = 1; | |||
| 821 | my $result; | |||
| 822 | ||||
| 823 | $self->_init_callbacks(); | |||
| 824 | eval { $result = $self->_parse_html_file($file, | |||
| 825 | $self->_html_options($opts) | |||
| 826 | ); }; | |||
| 827 | my $err = $@; | |||
| 828 | $self->{_State_} = 0; | |||
| 829 | if ($err) { | |||
| 830 | chomp $err unless ref $err; | |||
| 831 | $self->_cleanup_callbacks(); | |||
| 832 | croak $err; | |||
| 833 | } | |||
| 834 | ||||
| 835 | $self->_cleanup_callbacks(); | |||
| 836 | ||||
| 837 | return $result; | |||
| 838 | } | |||
| 839 | ||||
| 840 | sub parse_html_fh { | |||
| 841 | my ($self,$fh,$opts) = @_; | |||
| 842 | croak("parse_html_fh is not a class method! Create a parser object with XML::LibXML->new first!") unless ref $self; | |||
| 843 | croak("parse already in progress") if $self->{_State_}; | |||
| 844 | $self->{_State_} = 1; | |||
| 845 | ||||
| 846 | my $result; | |||
| 847 | $self->_init_callbacks(); | |||
| 848 | eval { $result = $self->_parse_html_fh( $fh, | |||
| 849 | $self->_html_options($opts) | |||
| 850 | ); }; | |||
| 851 | my $err = $@; | |||
| 852 | $self->{_State_} = 0; | |||
| 853 | if ($err) { | |||
| 854 | chomp $err unless ref $err; | |||
| 855 | $self->_cleanup_callbacks(); | |||
| 856 | croak $err; | |||
| 857 | } | |||
| 858 | $self->_cleanup_callbacks(); | |||
| 859 | ||||
| 860 | return $result; | |||
| 861 | } | |||
| 862 | ||||
| 863 | #-------------------------------------------------------------------------# | |||
| 864 | # push parser interface # | |||
| 865 | #-------------------------------------------------------------------------# | |||
| 866 | sub init_push { | |||
| 867 | my $self = shift; | |||
| 868 | ||||
| 869 | if ( defined $self->{CONTEXT} ) { | |||
| 870 | delete $self->{CONTEXT}; | |||
| 871 | } | |||
| 872 | ||||
| 873 | if ( defined $self->{SAX} ) { | |||
| 874 | $self->{CONTEXT} = $self->_start_push(1); | |||
| 875 | } | |||
| 876 | else { | |||
| 877 | $self->{CONTEXT} = $self->_start_push(0); | |||
| 878 | } | |||
| 879 | } | |||
| 880 | ||||
| 881 | sub push { | |||
| 882 | my $self = shift; | |||
| 883 | ||||
| 884 | $self->_init_callbacks(); | |||
| 885 | ||||
| 886 | if ( not defined $self->{CONTEXT} ) { | |||
| 887 | $self->init_push(); | |||
| 888 | } | |||
| 889 | ||||
| 890 | eval { | |||
| 891 | foreach ( @_ ) { | |||
| 892 | $self->_push( $self->{CONTEXT}, $_ ); | |||
| 893 | } | |||
| 894 | }; | |||
| 895 | my $err = $@; | |||
| 896 | $self->_cleanup_callbacks(); | |||
| 897 | if ( $err ) { | |||
| 898 | chomp $err unless ref $err; | |||
| 899 | croak $err; | |||
| 900 | } | |||
| 901 | } | |||
| 902 | ||||
| 903 | # this function should be promoted! | |||
| 904 | # the reason is because libxml2 uses xmlParseChunk() for this purpose! | |||
| 905 | sub parse_chunk { | |||
| 906 | my $self = shift; | |||
| 907 | my $chunk = shift; | |||
| 908 | my $terminate = shift; | |||
| 909 | ||||
| 910 | if ( not defined $self->{CONTEXT} ) { | |||
| 911 | $self->init_push(); | |||
| 912 | } | |||
| 913 | ||||
| 914 | if ( defined $chunk and length $chunk ) { | |||
| 915 | $self->_push( $self->{CONTEXT}, $chunk ); | |||
| 916 | } | |||
| 917 | ||||
| 918 | if ( $terminate ) { | |||
| 919 | return $self->finish_push(); | |||
| 920 | } | |||
| 921 | } | |||
| 922 | ||||
| 923 | ||||
| 924 | sub finish_push { | |||
| 925 | my $self = shift; | |||
| 926 | my $restore = shift || 0; | |||
| 927 | return undef unless defined $self->{CONTEXT}; | |||
| 928 | ||||
| 929 | my $retval; | |||
| 930 | ||||
| 931 | if ( defined $self->{SAX} ) { | |||
| 932 | eval { | |||
| 933 | $self->_end_sax_push( $self->{CONTEXT} ); | |||
| 934 | $retval = $self->{HANDLER}->end_document( {} ); | |||
| 935 | }; | |||
| 936 | } | |||
| 937 | else { | |||
| 938 | eval { $retval = $self->_end_push( $self->{CONTEXT}, $restore ); }; | |||
| 939 | } | |||
| 940 | delete $self->{CONTEXT}; | |||
| 941 | my $err = $@; | |||
| 942 | if ( $err ) { | |||
| 943 | chomp $err unless ref $err; | |||
| 944 | croak( $err ); | |||
| 945 | } | |||
| 946 | return $retval; | |||
| 947 | } | |||
| 948 | ||||
| 949 | 1 | 200ns | 200ns | 1; |
| 950 | ||||
| 951 | #-------------------------------------------------------------------------# | |||
| 952 | # XML::LibXML::Node Interface # | |||
| 953 | #-------------------------------------------------------------------------# | |||
| 954 | package XML::LibXML::Node; | |||
| 955 | ||||
| 956 | sub CLONE_SKIP { | |||
| 957 | return $XML::LibXML::__threads_shared ? 0 : 1; | |||
| 958 | } | |||
| 959 | ||||
| 960 | sub isSupported { | |||
| 961 | my $self = shift; | |||
| 962 | my $feature = shift; | |||
| 963 | return $self->can($feature) ? 1 : 0; | |||
| 964 | } | |||
| 965 | ||||
| 966 | sub getChildNodes { my $self = shift; return $self->childNodes(); } | |||
| 967 | ||||
| 968 | sub childNodes { | |||
| 969 | my $self = shift; | |||
| 970 | my @children = $self->_childNodes(); | |||
| 971 | return wantarray ? @children : XML::LibXML::NodeList->new_from_ref(\@children , 1); | |||
| 972 | } | |||
| 973 | ||||
| 974 | sub attributes { | |||
| 975 | my $self = shift; | |||
| 976 | my @attr = $self->_attributes(); | |||
| 977 | return wantarray ? @attr : XML::LibXML::NamedNodeMap->new( @attr ); | |||
| 978 | } | |||
| 979 | ||||
| 980 | ||||
| 981 | sub findnodes { | |||
| 982 | my ($node, $xpath) = @_; | |||
| 983 | my @nodes = $node->_findnodes($xpath); | |||
| 984 | if (wantarray) { | |||
| 985 | return @nodes; | |||
| 986 | } | |||
| 987 | else { | |||
| 988 | return XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 989 | } | |||
| 990 | } | |||
| 991 | ||||
| 992 | sub exists { | |||
| 993 | my ($node, $xpath) = @_; | |||
| 994 | my (undef, $value) = $node->_find($xpath,1); | |||
| 995 | return $value; | |||
| 996 | } | |||
| 997 | ||||
| 998 | sub findvalue { | |||
| 999 | my ($node, $xpath) = @_; | |||
| 1000 | my $res; | |||
| 1001 | $res = $node->find($xpath); | |||
| 1002 | return $res->to_literal->value; | |||
| 1003 | } | |||
| 1004 | ||||
| 1005 | sub findbool { | |||
| 1006 | my ($node, $xpath) = @_; | |||
| 1007 | my ($type, @params) = $node->_find($xpath,1); | |||
| 1008 | if ($type) { | |||
| 1009 | return $type->new(@params); | |||
| 1010 | } | |||
| 1011 | return undef; | |||
| 1012 | } | |||
| 1013 | ||||
| 1014 | sub find { | |||
| 1015 | my ($node, $xpath) = @_; | |||
| 1016 | my ($type, @params) = $node->_find($xpath,0); | |||
| 1017 | if ($type) { | |||
| 1018 | return $type->new(@params); | |||
| 1019 | } | |||
| 1020 | return undef; | |||
| 1021 | } | |||
| 1022 | ||||
| 1023 | sub setOwnerDocument { | |||
| 1024 | my ( $self, $doc ) = @_; | |||
| 1025 | $doc->adoptNode( $self ); | |||
| 1026 | } | |||
| 1027 | ||||
| 1028 | sub toStringC14N { | |||
| 1029 | my ($self, $comments, $xpath) = (shift, shift, shift); | |||
| 1030 | return $self->_toStringC14N( $comments || 0, | |||
| 1031 | (defined $xpath ? $xpath : undef), | |||
| 1032 | 0, | |||
| 1033 | undef ); | |||
| 1034 | } | |||
| 1035 | sub toStringEC14N { | |||
| 1036 | my ($self, $comments, $xpath, $inc_prefix_list) = @_; | |||
| 1037 | if (defined($inc_prefix_list) and !UNIVERSAL::isa($inc_prefix_list,'ARRAY')) { | |||
| 1038 | croak("toStringEC14N: inclusive_prefix_list must be undefined or ARRAY"); | |||
| 1039 | } | |||
| 1040 | return $self->_toStringC14N( $comments || 0, | |||
| 1041 | (defined $xpath ? $xpath : undef), | |||
| 1042 | 1, | |||
| 1043 | (defined $inc_prefix_list ? $inc_prefix_list : undef)); | |||
| 1044 | } | |||
| 1045 | ||||
| 1046 | 1 | 2µs | 2µs | *serialize_c14n = \&toStringC14N; |
| 1047 | 1 | 700ns | 700ns | *serialize_exc_c14n = \&toStringEC14N; |
| 1048 | ||||
| 1049 | 1 | 100ns | 100ns | 1; |
| 1050 | ||||
| 1051 | #-------------------------------------------------------------------------# | |||
| 1052 | # XML::LibXML::Document Interface # | |||
| 1053 | #-------------------------------------------------------------------------# | |||
| 1054 | package XML::LibXML::Document; | |||
| 1055 | ||||
| 1056 | 3 | 502µs | 167µs | use vars qw(@ISA); # spent 47µs making 1 call to vars::import |
| 1057 | 1 | 11µs | 11µs | @ISA = ('XML::LibXML::Node'); |
| 1058 | ||||
| 1059 | sub actualEncoding { | |||
| 1060 | my $doc = shift; | |||
| 1061 | my $enc = $doc->encoding; | |||
| 1062 | return (defined $enc and length $enc) ? $enc : 'UTF-8'; | |||
| 1063 | } | |||
| 1064 | ||||
| 1065 | sub setDocumentElement { | |||
| 1066 | my $doc = shift; | |||
| 1067 | my $element = shift; | |||
| 1068 | ||||
| 1069 | my $oldelem = $doc->documentElement; | |||
| 1070 | if ( defined $oldelem ) { | |||
| 1071 | $doc->removeChild($oldelem); | |||
| 1072 | } | |||
| 1073 | ||||
| 1074 | $doc->_setDocumentElement($element); | |||
| 1075 | } | |||
| 1076 | ||||
| 1077 | sub toString { | |||
| 1078 | my $self = shift; | |||
| 1079 | my $flag = shift; | |||
| 1080 | ||||
| 1081 | my $retval = ""; | |||
| 1082 | ||||
| 1083 | if ( defined $XML::LibXML::skipXMLDeclaration | |||
| 1084 | and $XML::LibXML::skipXMLDeclaration == 1 ) { | |||
| 1085 | foreach ( $self->childNodes ){ | |||
| 1086 | next if $_->nodeType == XML::LibXML::XML_DTD_NODE() | |||
| 1087 | and $XML::LibXML::skipDTD; | |||
| 1088 | $retval .= $_->toString; | |||
| 1089 | } | |||
| 1090 | } | |||
| 1091 | else { | |||
| 1092 | $flag ||= 0 unless defined $flag; | |||
| 1093 | $retval = $self->_toString($flag); | |||
| 1094 | } | |||
| 1095 | ||||
| 1096 | return $retval; | |||
| 1097 | } | |||
| 1098 | ||||
| 1099 | sub serialize { | |||
| 1100 | my $self = shift; | |||
| 1101 | return $self->toString( @_ ); | |||
| 1102 | } | |||
| 1103 | ||||
| 1104 | #-------------------------------------------------------------------------# | |||
| 1105 | # bad style xinclude processing # | |||
| 1106 | #-------------------------------------------------------------------------# | |||
| 1107 | sub process_xinclude { | |||
| 1108 | my $self = shift; | |||
| 1109 | my $opts = shift; | |||
| 1110 | XML::LibXML->new->processXIncludes( $self, $opts ); | |||
| 1111 | } | |||
| 1112 | ||||
| 1113 | sub insertProcessingInstruction { | |||
| 1114 | my $self = shift; | |||
| 1115 | my $target = shift; | |||
| 1116 | my $data = shift; | |||
| 1117 | ||||
| 1118 | my $pi = $self->createPI( $target, $data ); | |||
| 1119 | my $root = $self->documentElement; | |||
| 1120 | ||||
| 1121 | if ( defined $root ) { | |||
| 1122 | # this is actually not correct, but i guess it's what the user | |||
| 1123 | # intends | |||
| 1124 | $self->insertBefore( $pi, $root ); | |||
| 1125 | } | |||
| 1126 | else { | |||
| 1127 | # if no documentElement was found we just append the PI | |||
| 1128 | $self->appendChild( $pi ); | |||
| 1129 | } | |||
| 1130 | } | |||
| 1131 | ||||
| 1132 | sub insertPI { | |||
| 1133 | my $self = shift; | |||
| 1134 | $self->insertProcessingInstruction( @_ ); | |||
| 1135 | } | |||
| 1136 | ||||
| 1137 | #-------------------------------------------------------------------------# | |||
| 1138 | # DOM L3 Document functions. | |||
| 1139 | # added after robins implicit feature requst | |||
| 1140 | #-------------------------------------------------------------------------# | |||
| 1141 | 1 | 1µs | 1µs | *getElementsByTagName = \&XML::LibXML::Element::getElementsByTagName; |
| 1142 | 1 | 500ns | 500ns | *getElementsByTagNameNS = \&XML::LibXML::Element::getElementsByTagNameNS; |
| 1143 | 1 | 500ns | 500ns | *getElementsByLocalName = \&XML::LibXML::Element::getElementsByLocalName; |
| 1144 | ||||
| 1145 | 1 | 100ns | 100ns | 1; |
| 1146 | ||||
| 1147 | #-------------------------------------------------------------------------# | |||
| 1148 | # XML::LibXML::DocumentFragment Interface # | |||
| 1149 | #-------------------------------------------------------------------------# | |||
| 1150 | package XML::LibXML::DocumentFragment; | |||
| 1151 | ||||
| 1152 | 3 | 135µs | 45µs | use vars qw(@ISA); # spent 29µs making 1 call to vars::import |
| 1153 | 1 | 4µs | 4µs | @ISA = ('XML::LibXML::Node'); |
| 1154 | ||||
| 1155 | sub toString { | |||
| 1156 | my $self = shift; | |||
| 1157 | my $retval = ""; | |||
| 1158 | if ( $self->hasChildNodes() ) { | |||
| 1159 | foreach my $n ( $self->childNodes() ) { | |||
| 1160 | $retval .= $n->toString(@_); | |||
| 1161 | } | |||
| 1162 | } | |||
| 1163 | return $retval; | |||
| 1164 | } | |||
| 1165 | ||||
| 1166 | 1 | 1µs | 1µs | *serialize = \&toString; |
| 1167 | ||||
| 1168 | 1 | 100ns | 100ns | 1; |
| 1169 | ||||
| 1170 | #-------------------------------------------------------------------------# | |||
| 1171 | # XML::LibXML::Element Interface # | |||
| 1172 | #-------------------------------------------------------------------------# | |||
| 1173 | package XML::LibXML::Element; | |||
| 1174 | ||||
| 1175 | 3 | 40µs | 13µs | use vars qw(@ISA); # spent 24µs making 1 call to vars::import |
| 1176 | 1 | 4µs | 4µs | @ISA = ('XML::LibXML::Node'); |
| 1177 | 3 | 35µs | 12µs | use XML::LibXML qw(:ns :libxml); # spent 1.40ms making 1 call to XML::LibXML::import |
| 1178 | 3 | 1.25ms | 417µs | use Carp; # spent 57µs making 1 call to Exporter::import |
| 1179 | ||||
| 1180 | sub setNamespace { | |||
| 1181 | my $self = shift; | |||
| 1182 | my $n = $self->nodeName; | |||
| 1183 | if ( $self->_setNamespace(@_) ){ | |||
| 1184 | if ( scalar @_ < 3 || $_[2] == 1 ){ | |||
| 1185 | $self->setNodeName( $n ); | |||
| 1186 | } | |||
| 1187 | return 1; | |||
| 1188 | } | |||
| 1189 | return 0; | |||
| 1190 | } | |||
| 1191 | ||||
| 1192 | sub getAttribute { | |||
| 1193 | my $self = shift; | |||
| 1194 | my $name = $_[0]; | |||
| 1195 | if ( $name =~ /^xmlns(?::|$)/ ) { | |||
| 1196 | # user wants to get a namespace ... | |||
| 1197 | (my $prefix = $name )=~s/^xmlns:?//; | |||
| 1198 | $self->_getNamespaceDeclURI($prefix); | |||
| 1199 | } | |||
| 1200 | else { | |||
| 1201 | $self->_getAttribute(@_); | |||
| 1202 | } | |||
| 1203 | } | |||
| 1204 | ||||
| 1205 | sub setAttribute { | |||
| 1206 | my ( $self, $name, $value ) = @_; | |||
| 1207 | if ( $name =~ /^xmlns(?::|$)/ ) { | |||
| 1208 | # user wants to set the special attribute for declaring XML namespace ... | |||
| 1209 | ||||
| 1210 | # this is fine but not exactly DOM conformant behavior, btw (according to DOM we should | |||
| 1211 | # probably declare an attribute which looks like XML namespace declaration | |||
| 1212 | # but isn't) | |||
| 1213 | (my $nsprefix = $name )=~s/^xmlns:?//; | |||
| 1214 | my $nn = $self->nodeName; | |||
| 1215 | if ( $nn =~ /^\Q${nsprefix}\E:/ ) { | |||
| 1216 | # the element has the same prefix | |||
| 1217 | $self->setNamespaceDeclURI($nsprefix,$value) || | |||
| 1218 | $self->setNamespace($value,$nsprefix,1); | |||
| 1219 | ## | |||
| 1220 | ## We set the namespace here. | |||
| 1221 | ## This is helpful, as in: | |||
| 1222 | ## | |||
| 1223 | ## | $e = XML::LibXML::Element->new('foo:bar'); | |||
| 1224 | ## | $e->setAttribute('xmlns:foo','http://yoyodine') | |||
| 1225 | ## | |||
| 1226 | } | |||
| 1227 | else { | |||
| 1228 | # just modify the namespace | |||
| 1229 | $self->setNamespaceDeclURI($nsprefix, $value) || | |||
| 1230 | $self->setNamespace($value,$nsprefix,0); | |||
| 1231 | } | |||
| 1232 | } | |||
| 1233 | else { | |||
| 1234 | $self->_setAttribute($name, $value); | |||
| 1235 | } | |||
| 1236 | } | |||
| 1237 | ||||
| 1238 | sub getAttributeNS { | |||
| 1239 | my $self = shift; | |||
| 1240 | my ($nsURI, $name) = @_; | |||
| 1241 | croak("invalid attribute name") if !defined($name) or $name eq q{}; | |||
| 1242 | if ( defined($nsURI) and $nsURI eq XML_XMLNS_NS ) { | |||
| 1243 | $self->_getNamespaceDeclURI($name eq 'xmlns' ? undef : $name); | |||
| 1244 | } | |||
| 1245 | else { | |||
| 1246 | $self->_getAttributeNS(@_); | |||
| 1247 | } | |||
| 1248 | } | |||
| 1249 | ||||
| 1250 | sub setAttributeNS { | |||
| 1251 | my ($self, $nsURI, $qname, $value)=@_; | |||
| 1252 | unless (defined $qname and length $qname) { | |||
| 1253 | croak("bad name"); | |||
| 1254 | } | |||
| 1255 | if (defined($nsURI) and $nsURI eq XML_XMLNS_NS) { | |||
| 1256 | if ($qname !~ /^xmlns(?::|$)/) { | |||
| 1257 | croak("NAMESPACE ERROR: Namespace declartions must have the prefix 'xmlns'"); | |||
| 1258 | } | |||
| 1259 | $self->setAttribute($qname,$value); # see implementation above | |||
| 1260 | return; | |||
| 1261 | } | |||
| 1262 | if ($qname=~/:/ and not (defined($nsURI) and length($nsURI))) { | |||
| 1263 | croak("NAMESPACE ERROR: Attribute without a prefix cannot be in a namespace"); | |||
| 1264 | } | |||
| 1265 | if ($qname=~/^xmlns(?:$|:)/) { | |||
| 1266 | croak("NAMESPACE ERROR: 'xmlns' prefix and qualified-name are reserved for the namespace ".XML_XMLNS_NS); | |||
| 1267 | } | |||
| 1268 | if ($qname=~/^xml:/ and not (defined $nsURI and $nsURI eq XML_XML_NS)) { | |||
| 1269 | croak("NAMESPACE ERROR: 'xml' prefix is reserved for the namespace ".XML_XML_NS); | |||
| 1270 | } | |||
| 1271 | $self->_setAttributeNS( defined $nsURI ? $nsURI : undef, $qname, $value ); | |||
| 1272 | } | |||
| 1273 | ||||
| 1274 | sub getElementsByTagName { | |||
| 1275 | my ( $node , $name ) = @_; | |||
| 1276 | my $xpath = $name eq '*' ? "descendant::*" : "descendant::*[name()='$name']"; | |||
| 1277 | my @nodes = $node->_findnodes($xpath); | |||
| 1278 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1279 | } | |||
| 1280 | ||||
| 1281 | sub getElementsByTagNameNS { | |||
| 1282 | my ( $node, $nsURI, $name ) = @_; | |||
| 1283 | my $xpath; | |||
| 1284 | if ( $name eq '*' ) { | |||
| 1285 | if ( $nsURI eq '*' ) { | |||
| 1286 | $xpath = "descendant::*"; | |||
| 1287 | } else { | |||
| 1288 | $xpath = "descendant::*[namespace-uri()='$nsURI']"; | |||
| 1289 | } | |||
| 1290 | } elsif ( $nsURI eq '*' ) { | |||
| 1291 | $xpath = "descendant::*[local-name()='$name']"; | |||
| 1292 | } else { | |||
| 1293 | $xpath = "descendant::*[local-name()='$name' and namespace-uri()='$nsURI']"; | |||
| 1294 | } | |||
| 1295 | my @nodes = $node->_findnodes($xpath); | |||
| 1296 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1297 | } | |||
| 1298 | ||||
| 1299 | sub getElementsByLocalName { | |||
| 1300 | my ( $node,$name ) = @_; | |||
| 1301 | my $xpath; | |||
| 1302 | if ($name eq '*') { | |||
| 1303 | $xpath = "descendant::*"; | |||
| 1304 | } else { | |||
| 1305 | $xpath = "descendant::*[local-name()='$name']"; | |||
| 1306 | } | |||
| 1307 | my @nodes = $node->_findnodes($xpath); | |||
| 1308 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1309 | } | |||
| 1310 | ||||
| 1311 | sub getChildrenByTagName { | |||
| 1312 | my ( $node, $name ) = @_; | |||
| 1313 | my @nodes; | |||
| 1314 | if ($name eq '*') { | |||
| 1315 | @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() } | |||
| 1316 | $node->childNodes(); | |||
| 1317 | } else { | |||
| 1318 | @nodes = grep { $_->nodeName eq $name } $node->childNodes(); | |||
| 1319 | } | |||
| 1320 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1321 | } | |||
| 1322 | ||||
| 1323 | sub getChildrenByLocalName { | |||
| 1324 | my ( $node, $name ) = @_; | |||
| 1325 | my @nodes; | |||
| 1326 | if ($name eq '*') { | |||
| 1327 | @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() } | |||
| 1328 | $node->childNodes(); | |||
| 1329 | } else { | |||
| 1330 | @nodes = grep { $_->nodeType == XML_ELEMENT_NODE() and | |||
| 1331 | $_->localName eq $name } $node->childNodes(); | |||
| 1332 | } | |||
| 1333 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1334 | } | |||
| 1335 | ||||
| 1336 | sub getChildrenByTagNameNS { | |||
| 1337 | my ( $node, $nsURI, $name ) = @_; | |||
| 1338 | my @nodes = $node->_getChildrenByTagNameNS($nsURI,$name); | |||
| 1339 | return wantarray ? @nodes : XML::LibXML::NodeList->new_from_ref(\@nodes, 1); | |||
| 1340 | } | |||
| 1341 | ||||
| 1342 | sub appendWellBalancedChunk { | |||
| 1343 | my ( $self, $chunk ) = @_; | |||
| 1344 | ||||
| 1345 | my $local_parser = XML::LibXML->new(); | |||
| 1346 | my $frag = $local_parser->parse_xml_chunk( $chunk ); | |||
| 1347 | ||||
| 1348 | $self->appendChild( $frag ); | |||
| 1349 | } | |||
| 1350 | ||||
| 1351 | 1 | 200ns | 200ns | 1; |
| 1352 | ||||
| 1353 | #-------------------------------------------------------------------------# | |||
| 1354 | # XML::LibXML::Text Interface # | |||
| 1355 | #-------------------------------------------------------------------------# | |||
| 1356 | package XML::LibXML::Text; | |||
| 1357 | ||||
| 1358 | 3 | 359µs | 120µs | use vars qw(@ISA); # spent 29µs making 1 call to vars::import |
| 1359 | 1 | 3µs | 3µs | @ISA = ('XML::LibXML::Node'); |
| 1360 | ||||
| 1361 | sub attributes { return undef; } | |||
| 1362 | ||||
| 1363 | sub deleteDataString { | |||
| 1364 | my $node = shift; | |||
| 1365 | my $string = shift; | |||
| 1366 | my $all = shift; | |||
| 1367 | my $data = $node->nodeValue(); | |||
| 1368 | $string =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\\$1/g; | |||
| 1369 | if ( $all ) { | |||
| 1370 | $data =~ s/$string//g; | |||
| 1371 | } | |||
| 1372 | else { | |||
| 1373 | $data =~ s/$string//; | |||
| 1374 | } | |||
| 1375 | $node->setData( $data ); | |||
| 1376 | } | |||
| 1377 | ||||
| 1378 | sub replaceDataString { | |||
| 1379 | my ( $node, $left, $right,$all ) = @_; | |||
| 1380 | ||||
| 1381 | #ashure we exchange the strings and not expressions! | |||
| 1382 | $left =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\\$1/g; | |||
| 1383 | my $datastr = $node->nodeValue(); | |||
| 1384 | if ( $all ) { | |||
| 1385 | $datastr =~ s/$left/$right/g; | |||
| 1386 | } | |||
| 1387 | else{ | |||
| 1388 | $datastr =~ s/$left/$right/; | |||
| 1389 | } | |||
| 1390 | $node->setData( $datastr ); | |||
| 1391 | } | |||
| 1392 | ||||
| 1393 | sub replaceDataRegEx { | |||
| 1394 | my ( $node, $leftre, $rightre, $flags ) = @_; | |||
| 1395 | return unless defined $leftre; | |||
| 1396 | $rightre ||= ""; | |||
| 1397 | ||||
| 1398 | my $datastr = $node->nodeValue(); | |||
| 1399 | my $restr = "s/" . $leftre . "/" . $rightre . "/"; | |||
| 1400 | $restr .= $flags if defined $flags; | |||
| 1401 | ||||
| 1402 | eval '$datastr =~ '. $restr; | |||
| 1403 | ||||
| 1404 | $node->setData( $datastr ); | |||
| 1405 | } | |||
| 1406 | ||||
| 1407 | 1 | 100ns | 100ns | 1; |
| 1408 | ||||
| 1409 | package XML::LibXML::Comment; | |||
| 1410 | ||||
| 1411 | 3 | 48µs | 16µs | use vars qw(@ISA); # spent 25µs making 1 call to vars::import |
| 1412 | 1 | 5µs | 5µs | @ISA = ('XML::LibXML::Text'); |
| 1413 | ||||
| 1414 | 1 | 100ns | 100ns | 1; |
| 1415 | ||||
| 1416 | package XML::LibXML::CDATASection; | |||
| 1417 | ||||
| 1418 | 3 | 49µs | 16µs | use vars qw(@ISA); # spent 21µs making 1 call to vars::import |
| 1419 | 1 | 4µs | 4µs | @ISA = ('XML::LibXML::Text'); |
| 1420 | ||||
| 1421 | 1 | 100ns | 100ns | 1; |
| 1422 | ||||
| 1423 | #-------------------------------------------------------------------------# | |||
| 1424 | # XML::LibXML::Attribute Interface # | |||
| 1425 | #-------------------------------------------------------------------------# | |||
| 1426 | package XML::LibXML::Attr; | |||
| 1427 | 3 | 108µs | 36µs | use vars qw( @ISA ) ; # spent 21µs making 1 call to vars::import |
| 1428 | 1 | 3µs | 3µs | @ISA = ('XML::LibXML::Node') ; |
| 1429 | ||||
| 1430 | sub setNamespace { | |||
| 1431 | my ($self,$href,$prefix) = @_; | |||
| 1432 | my $n = $self->nodeName; | |||
| 1433 | if ( $self->_setNamespace($href,$prefix) ) { | |||
| 1434 | $self->setNodeName($n); | |||
| 1435 | return 1; | |||
| 1436 | } | |||
| 1437 | ||||
| 1438 | return 0; | |||
| 1439 | } | |||
| 1440 | ||||
| 1441 | 1 | 100ns | 100ns | 1; |
| 1442 | ||||
| 1443 | #-------------------------------------------------------------------------# | |||
| 1444 | # XML::LibXML::Dtd Interface # | |||
| 1445 | #-------------------------------------------------------------------------# | |||
| 1446 | # this is still under construction | |||
| 1447 | # | |||
| 1448 | package XML::LibXML::Dtd; | |||
| 1449 | 3 | 56µs | 19µs | use vars qw( @ISA ); # spent 22µs making 1 call to vars::import |
| 1450 | 1 | 4µs | 4µs | @ISA = ('XML::LibXML::Node'); |
| 1451 | ||||
| 1452 | # at least DESTROY and CLONE_SKIP must be inherited | |||
| 1453 | ||||
| 1454 | 1 | 200ns | 200ns | 1; |
| 1455 | ||||
| 1456 | #-------------------------------------------------------------------------# | |||
| 1457 | # XML::LibXML::PI Interface # | |||
| 1458 | #-------------------------------------------------------------------------# | |||
| 1459 | package XML::LibXML::PI; | |||
| 1460 | 3 | 423µs | 141µs | use vars qw( @ISA ); # spent 22µs making 1 call to vars::import |
| 1461 | 1 | 3µs | 3µs | @ISA = ('XML::LibXML::Node'); |
| 1462 | ||||
| 1463 | sub setData { | |||
| 1464 | my $pi = shift; | |||
| 1465 | ||||
| 1466 | my $string = ""; | |||
| 1467 | if ( scalar @_ == 1 ) { | |||
| 1468 | $string = shift; | |||
| 1469 | } | |||
| 1470 | else { | |||
| 1471 | my %h = @_; | |||
| 1472 | $string = join " ", map {$_.'="'.$h{$_}.'"'} keys %h; | |||
| 1473 | } | |||
| 1474 | ||||
| 1475 | # the spec says any char but "?>" [17] | |||
| 1476 | $pi->_setData( $string ) unless $string =~ /\?>/; | |||
| 1477 | } | |||
| 1478 | ||||
| 1479 | 1 | 100ns | 100ns | 1; |
| 1480 | ||||
| 1481 | #-------------------------------------------------------------------------# | |||
| 1482 | # XML::LibXML::Namespace Interface # | |||
| 1483 | #-------------------------------------------------------------------------# | |||
| 1484 | package XML::LibXML::Namespace; | |||
| 1485 | ||||
| 1486 | sub CLONE_SKIP { 1 } | |||
| 1487 | ||||
| 1488 | # this is infact not a node! | |||
| 1489 | sub prefix { return "xmlns"; } | |||
| 1490 | sub getPrefix { return "xmlns"; } | |||
| 1491 | sub getNamespaceURI { return "http://www.w3.org/2000/xmlns/" }; | |||
| 1492 | ||||
| 1493 | sub getNamespaces { return (); } | |||
| 1494 | ||||
| 1495 | sub nodeName { | |||
| 1496 | my $self = shift; | |||
| 1497 | my $nsP = $self->localname; | |||
| 1498 | return ( defined($nsP) && length($nsP) ) ? "xmlns:$nsP" : "xmlns"; | |||
| 1499 | } | |||
| 1500 | sub name { goto &nodeName } | |||
| 1501 | sub getName { goto &nodeName } | |||
| 1502 | ||||
| 1503 | sub isEqualNode { | |||
| 1504 | my ( $self, $ref ) = @_; | |||
| 1505 | if ( ref($ref) eq "XML::LibXML::Namespace" ) { | |||
| 1506 | return $self->_isEqual($ref); | |||
| 1507 | } | |||
| 1508 | return 0; | |||
| 1509 | } | |||
| 1510 | ||||
| 1511 | sub isSameNode { | |||
| 1512 | my ( $self, $ref ) = @_; | |||
| 1513 | if ( $$self == $$ref ){ | |||
| 1514 | return 1; | |||
| 1515 | } | |||
| 1516 | return 0; | |||
| 1517 | } | |||
| 1518 | ||||
| 1519 | 1 | 100ns | 100ns | 1; |
| 1520 | ||||
| 1521 | #-------------------------------------------------------------------------# | |||
| 1522 | # XML::LibXML::NamedNodeMap Interface # | |||
| 1523 | #-------------------------------------------------------------------------# | |||
| 1524 | package XML::LibXML::NamedNodeMap; | |||
| 1525 | ||||
| 1526 | 3 | 634µs | 211µs | use XML::LibXML::Common qw(:libxml); # spent 225µs making 1 call to Exporter::import |
| 1527 | ||||
| 1528 | sub CLONE_SKIP { | |||
| 1529 | return $XML::LibXML::__threads_shared ? 0 : 1; | |||
| 1530 | } | |||
| 1531 | ||||
| 1532 | sub new { | |||
| 1533 | my $class = shift; | |||
| 1534 | my $self = bless { Nodes => [@_] }, $class; | |||
| 1535 | $self->{NodeMap} = { map { $_->nodeName => $_ } @_ }; | |||
| 1536 | return $self; | |||
| 1537 | } | |||
| 1538 | ||||
| 1539 | sub length { return scalar( @{$_[0]->{Nodes}} ); } | |||
| 1540 | sub nodes { return $_[0]->{Nodes}; } | |||
| 1541 | sub item { $_[0]->{Nodes}->[$_[1]]; } | |||
| 1542 | ||||
| 1543 | sub getNamedItem { | |||
| 1544 | my $self = shift; | |||
| 1545 | my $name = shift; | |||
| 1546 | ||||
| 1547 | return $self->{NodeMap}->{$name}; | |||
| 1548 | } | |||
| 1549 | ||||
| 1550 | sub setNamedItem { | |||
| 1551 | my $self = shift; | |||
| 1552 | my $node = shift; | |||
| 1553 | ||||
| 1554 | my $retval; | |||
| 1555 | if ( defined $node ) { | |||
| 1556 | if ( scalar @{$self->{Nodes}} ) { | |||
| 1557 | my $name = $node->nodeName(); | |||
| 1558 | if ( $node->nodeType() == XML_NAMESPACE_DECL ) { | |||
| 1559 | return; | |||
| 1560 | } | |||
| 1561 | if ( defined $self->{NodeMap}->{$name} ) { | |||
| 1562 | if ( $node->isSameNode( $self->{NodeMap}->{$name} ) ) { | |||
| 1563 | return; | |||
| 1564 | } | |||
| 1565 | $retval = $self->{NodeMap}->{$name}->replaceNode( $node ); | |||
| 1566 | } | |||
| 1567 | else { | |||
| 1568 | $self->{Nodes}->[0]->addSibling($node); | |||
| 1569 | } | |||
| 1570 | ||||
| 1571 | $self->{NodeMap}->{$name} = $node; | |||
| 1572 | push @{$self->{Nodes}}, $node; | |||
| 1573 | } | |||
| 1574 | else { | |||
| 1575 | # not done yet | |||
| 1576 | # can this be properly be done??? | |||
| 1577 | warn "not done yet\n"; | |||
| 1578 | } | |||
| 1579 | } | |||
| 1580 | return $retval; | |||
| 1581 | } | |||
| 1582 | ||||
| 1583 | sub removeNamedItem { | |||
| 1584 | my $self = shift; | |||
| 1585 | my $name = shift; | |||
| 1586 | my $retval; | |||
| 1587 | if ( $name =~ /^xmlns/ ) { | |||
| 1588 | warn "not done yet\n"; | |||
| 1589 | } | |||
| 1590 | elsif ( exists $self->{NodeMap}->{$name} ) { | |||
| 1591 | $retval = $self->{NodeMap}->{$name}; | |||
| 1592 | $retval->unbindNode; | |||
| 1593 | delete $self->{NodeMap}->{$name}; | |||
| 1594 | $self->{Nodes} = [grep {not($retval->isSameNode($_))} @{$self->{Nodes}}]; | |||
| 1595 | } | |||
| 1596 | ||||
| 1597 | return $retval; | |||
| 1598 | } | |||
| 1599 | ||||
| 1600 | sub getNamedItemNS { | |||
| 1601 | my $self = shift; | |||
| 1602 | my $nsURI = shift; | |||
| 1603 | my $name = shift; | |||
| 1604 | return undef; | |||
| 1605 | } | |||
| 1606 | ||||
| 1607 | sub setNamedItemNS { | |||
| 1608 | my $self = shift; | |||
| 1609 | my $nsURI = shift; | |||
| 1610 | my $node = shift; | |||
| 1611 | return undef; | |||
| 1612 | } | |||
| 1613 | ||||
| 1614 | sub removeNamedItemNS { | |||
| 1615 | my $self = shift; | |||
| 1616 | my $nsURI = shift; | |||
| 1617 | my $name = shift; | |||
| 1618 | return undef; | |||
| 1619 | } | |||
| 1620 | ||||
| 1621 | 1 | 100ns | 100ns | 1; |
| 1622 | ||||
| 1623 | package XML::LibXML::_SAXParser; | |||
| 1624 | ||||
| 1625 | # this is pseudo class!!! and it will be removed as soon all functions | |||
| 1626 | # moved to XS level | |||
| 1627 | ||||
| 1628 | 3 | 599µs | 200µs | use XML::SAX::Exception; # spent 9µs making 1 call to UNIVERSAL::import |
| 1629 | ||||
| 1630 | sub CLONE_SKIP { | |||
| 1631 | return $XML::LibXML::__threads_shared ? 0 : 1; | |||
| 1632 | } | |||
| 1633 | ||||
| 1634 | # these functions will use SAX exceptions as soon i know how things really work | |||
| 1635 | sub warning { | |||
| 1636 | my ( $parser, $message, $line, $col ) = @_; | |||
| 1637 | my $error = XML::SAX::Exception::Parse->new( LineNumber => $line, | |||
| 1638 | ColumnNumber => $col, | |||
| 1639 | Message => $message, ); | |||
| 1640 | $parser->{HANDLER}->warning( $error ); | |||
| 1641 | } | |||
| 1642 | ||||
| 1643 | sub error { | |||
| 1644 | my ( $parser, $message, $line, $col ) = @_; | |||
| 1645 | ||||
| 1646 | my $error = XML::SAX::Exception::Parse->new( LineNumber => $line, | |||
| 1647 | ColumnNumber => $col, | |||
| 1648 | Message => $message, ); | |||
| 1649 | $parser->{HANDLER}->error( $error ); | |||
| 1650 | } | |||
| 1651 | ||||
| 1652 | sub fatal_error { | |||
| 1653 | my ( $parser, $message, $line, $col ) = @_; | |||
| 1654 | my $error = XML::SAX::Exception::Parse->new( LineNumber => $line, | |||
| 1655 | ColumnNumber => $col, | |||
| 1656 | Message => $message, ); | |||
| 1657 | $parser->{HANDLER}->fatal_error( $error ); | |||
| 1658 | } | |||
| 1659 | ||||
| 1660 | 1 | 100ns | 100ns | 1; |
| 1661 | ||||
| 1662 | package XML::LibXML::RelaxNG; | |||
| 1663 | ||||
| 1664 | sub CLONE_SKIP { 1 } | |||
| 1665 | ||||
| 1666 | sub new { | |||
| 1667 | my $class = shift; | |||
| 1668 | my %args = @_; | |||
| 1669 | ||||
| 1670 | my $self = undef; | |||
| 1671 | if ( defined $args{location} ) { | |||
| 1672 | $self = $class->parse_location( $args{location} ); | |||
| 1673 | } | |||
| 1674 | elsif ( defined $args{string} ) { | |||
| 1675 | $self = $class->parse_buffer( $args{string} ); | |||
| 1676 | } | |||
| 1677 | elsif ( defined $args{DOM} ) { | |||
| 1678 | $self = $class->parse_document( $args{DOM} ); | |||
| 1679 | } | |||
| 1680 | ||||
| 1681 | return $self; | |||
| 1682 | } | |||
| 1683 | ||||
| 1684 | 1 | 100ns | 100ns | 1; |
| 1685 | ||||
| 1686 | package XML::LibXML::Schema; | |||
| 1687 | ||||
| 1688 | sub CLONE_SKIP { 1 } | |||
| 1689 | ||||
| 1690 | sub new { | |||
| 1691 | my $class = shift; | |||
| 1692 | my %args = @_; | |||
| 1693 | ||||
| 1694 | my $self = undef; | |||
| 1695 | if ( defined $args{location} ) { | |||
| 1696 | $self = $class->parse_location( $args{location} ); | |||
| 1697 | } | |||
| 1698 | elsif ( defined $args{string} ) { | |||
| 1699 | $self = $class->parse_buffer( $args{string} ); | |||
| 1700 | } | |||
| 1701 | ||||
| 1702 | return $self; | |||
| 1703 | } | |||
| 1704 | ||||
| 1705 | 1 | 100ns | 100ns | 1; |
| 1706 | ||||
| 1707 | #-------------------------------------------------------------------------# | |||
| 1708 | # XML::LibXML::Pattern Interface # | |||
| 1709 | #-------------------------------------------------------------------------# | |||
| 1710 | ||||
| 1711 | package XML::LibXML::Pattern; | |||
| 1712 | ||||
| 1713 | sub CLONE_SKIP { 1 } | |||
| 1714 | ||||
| 1715 | sub new { | |||
| 1716 | my $class = shift; | |||
| 1717 | my ($pattern,$ns_map)=@_; | |||
| 1718 | my $self = undef; | |||
| 1719 | ||||
| 1720 | unless (UNIVERSAL::can($class,'_compilePattern')) { | |||
| 1721 | croak("Cannot create XML::LibXML::Pattern - ". | |||
| 1722 | "your libxml2 is compiled without pattern support!"); | |||
| 1723 | } | |||
| 1724 | ||||
| 1725 | if (ref($ns_map) eq 'HASH') { | |||
| 1726 | # translate prefix=>URL hash to a (URL,prefix) list | |||
| 1727 | $self = $class->_compilePattern($pattern,0,[reverse %$ns_map]); | |||
| 1728 | } else { | |||
| 1729 | $self = $class->_compilePattern($pattern,0); | |||
| 1730 | } | |||
| 1731 | return $self; | |||
| 1732 | } | |||
| 1733 | ||||
| 1734 | 1 | 100ns | 100ns | 1; |
| 1735 | ||||
| 1736 | #-------------------------------------------------------------------------# | |||
| 1737 | # XML::LibXML::XPathExpression Interface # | |||
| 1738 | #-------------------------------------------------------------------------# | |||
| 1739 | ||||
| 1740 | package XML::LibXML::XPathExpression; | |||
| 1741 | ||||
| 1742 | sub CLONE_SKIP { 1 } | |||
| 1743 | ||||
| 1744 | 1 | 100ns | 100ns | 1; |
| 1745 | ||||
| 1746 | ||||
| 1747 | #-------------------------------------------------------------------------# | |||
| 1748 | # XML::LibXML::InputCallback Interface # | |||
| 1749 | #-------------------------------------------------------------------------# | |||
| 1750 | package XML::LibXML::InputCallback; | |||
| 1751 | ||||
| 1752 | 3 | 51µs | 17µs | use vars qw($_CUR_CB @_GLOBAL_CALLBACKS @_CB_STACK); # spent 46µs making 1 call to vars::import |
| 1753 | ||||
| 1754 | BEGIN { | |||
| 1755 | 3 | 2µs | 667ns | $_CUR_CB = undef; |
| 1756 | @_GLOBAL_CALLBACKS = (); | |||
| 1757 | @_CB_STACK = (); | |||
| 1758 | 1 | 738µs | 738µs | } |
| 1759 | ||||
| 1760 | sub CLONE_SKIP { | |||
| 1761 | return $XML::LibXML::__threads_shared ? 0 : 1; | |||
| 1762 | } | |||
| 1763 | ||||
| 1764 | #-------------------------------------------------------------------------# | |||
| 1765 | # global callbacks # | |||
| 1766 | #-------------------------------------------------------------------------# | |||
| 1767 | sub _callback_match { | |||
| 1768 | 4 | 6µs | 1µs | my $uri = shift; |
| 1769 | my $retval = 0; | |||
| 1770 | ||||
| 1771 | # loop through the callbacks and and find the first matching | |||
| 1772 | # The callbacks are stored in execution order (reverse stack order) | |||
| 1773 | # any new global callbacks are shifted to the callback stack. | |||
| 1774 | foreach my $cb ( @_GLOBAL_CALLBACKS ) { | |||
| 1775 | ||||
| 1776 | # callbacks have to return 1, 0 or undef, while 0 and undef | |||
| 1777 | # are handled the same way. | |||
| 1778 | # in fact, if callbacks return other values, the global match | |||
| 1779 | # assumes silently that the callback failed. | |||
| 1780 | ||||
| 1781 | $retval = $cb->[0]->($uri); | |||
| 1782 | ||||
| 1783 | if ( defined $retval and $retval == 1 ) { | |||
| 1784 | # make the other callbacks use this callback | |||
| 1785 | $_CUR_CB = $cb; | |||
| 1786 | unshift @_CB_STACK, $cb; | |||
| 1787 | last; | |||
| 1788 | } | |||
| 1789 | } | |||
| 1790 | ||||
| 1791 | return $retval; | |||
| 1792 | } | |||
| 1793 | ||||
| 1794 | sub _callback_open { | |||
| 1795 | my $uri = shift; | |||
| 1796 | my $retval = undef; | |||
| 1797 | ||||
| 1798 | # the open callback has to return a defined value. | |||
| 1799 | # if one works on files this can be a file handle. But | |||
| 1800 | # depending on the needs of the callback it also can be a | |||
| 1801 | # database handle or a integer labeling a certain dataset. | |||
| 1802 | ||||
| 1803 | if ( defined $_CUR_CB ) { | |||
| 1804 | $retval = $_CUR_CB->[1]->( $uri ); | |||
| 1805 | ||||
| 1806 | # reset the callbacks, if one callback cannot open an uri | |||
| 1807 | if ( not defined $retval or $retval == 0 ) { | |||
| 1808 | shift @_CB_STACK; | |||
| 1809 | $_CUR_CB = $_CB_STACK[0]; | |||
| 1810 | } | |||
| 1811 | } | |||
| 1812 | ||||
| 1813 | return $retval; | |||
| 1814 | } | |||
| 1815 | ||||
| 1816 | sub _callback_read { | |||
| 1817 | my $fh = shift; | |||
| 1818 | my $buflen = shift; | |||
| 1819 | ||||
| 1820 | my $retval = undef; | |||
| 1821 | ||||
| 1822 | if ( defined $_CUR_CB ) { | |||
| 1823 | $retval = $_CUR_CB->[2]->( $fh, $buflen ); | |||
| 1824 | } | |||
| 1825 | ||||
| 1826 | return $retval; | |||
| 1827 | } | |||
| 1828 | ||||
| 1829 | sub _callback_close { | |||
| 1830 | my $fh = shift; | |||
| 1831 | my $retval = 0; | |||
| 1832 | ||||
| 1833 | if ( defined $_CUR_CB ) { | |||
| 1834 | $retval = $_CUR_CB->[3]->( $fh ); | |||
| 1835 | shift @_CB_STACK; | |||
| 1836 | $_CUR_CB = $_CB_STACK[0]; | |||
| 1837 | } | |||
| 1838 | ||||
| 1839 | return $retval; | |||
| 1840 | } | |||
| 1841 | ||||
| 1842 | #-------------------------------------------------------------------------# | |||
| 1843 | # member functions and methods # | |||
| 1844 | #-------------------------------------------------------------------------# | |||
| 1845 | ||||
| 1846 | # spent 15µs within XML::LibXML::InputCallback::new which was called
# once (15µs+0s) by XML::LibXML::_init_callbacks at line 473 | |||
| 1847 | 2 | 10µs | 5µs | my $CLASS = shift; |
| 1848 | return bless {'_CALLBACKS' => []}, $CLASS; | |||
| 1849 | } | |||
| 1850 | ||||
| 1851 | # add a callback set to the callback stack | |||
| 1852 | # synopsis: $icb->register_callbacks( [$match_cb, $open_cb, $read_cb, $close_cb] ); | |||
| 1853 | sub register_callbacks { | |||
| 1854 | my $self = shift; | |||
| 1855 | my $cbset = shift; | |||
| 1856 | ||||
| 1857 | # test if callback set is complete | |||
| 1858 | if ( ref $cbset eq "ARRAY" and scalar( @$cbset ) == 4 ) { | |||
| 1859 | unshift @{$self->{_CALLBACKS}}, $cbset; | |||
| 1860 | } | |||
| 1861 | } | |||
| 1862 | ||||
| 1863 | # remove a callback set to the callback stack | |||
| 1864 | # if a callback set is passed, this function will check for the match function | |||
| 1865 | # spent 12µs within XML::LibXML::InputCallback::unregister_callbacks which was called
# once (12µs+0s) by XML::LibXML::_cleanup_callbacks at line 493 | |||
| 1866 | 4 | 6µs | 1µs | my $self = shift; |
| 1867 | my $cbset = shift; | |||
| 1868 | if ( ref $cbset eq "ARRAY" and scalar( @$cbset ) == 4 ) { | |||
| 1869 | $self->{_CALLBACKS} = [grep { $_->[0] != $cbset->[0] } @{$self->{_CALLBACKS}}]; | |||
| 1870 | } | |||
| 1871 | else { | |||
| 1872 | shift @{$self->{_CALLBACKS}}; | |||
| 1873 | } | |||
| 1874 | } | |||
| 1875 | ||||
| 1876 | # make libxml2 use the callbacks | |||
| 1877 | # spent 40µs (12+28) within XML::LibXML::InputCallback::init_callbacks which was called
# once (12µs+28µs) by XML::LibXML::_init_callbacks at line 486 | |||
| 1878 | 6 | 35µs | 6µs | my $self = shift; |
| 1879 | ||||
| 1880 | $_CUR_CB = undef; | |||
| 1881 | @_CB_STACK = (); | |||
| 1882 | ||||
| 1883 | @_GLOBAL_CALLBACKS = @{ $self->{_CALLBACKS} }; | |||
| 1884 | ||||
| 1885 | if ( defined $XML::LibXML::match_cb and | |||
| 1886 | defined $XML::LibXML::open_cb and | |||
| 1887 | defined $XML::LibXML::read_cb and | |||
| 1888 | defined $XML::LibXML::close_cb ) { | |||
| 1889 | push @_GLOBAL_CALLBACKS, [$XML::LibXML::match_cb, | |||
| 1890 | $XML::LibXML::open_cb, | |||
| 1891 | $XML::LibXML::read_cb, | |||
| 1892 | $XML::LibXML::close_cb]; | |||
| 1893 | } | |||
| 1894 | ||||
| 1895 | $self->lib_init_callbacks(); # spent 28µs making 1 call to XML::LibXML::InputCallback::lib_init_callbacks | |||
| 1896 | } | |||
| 1897 | ||||
| 1898 | # reset libxml2's callbacks | |||
| 1899 | # spent 22µs (11+11) within XML::LibXML::InputCallback::cleanup_callbacks which was called
# once (11µs+11µs) by XML::LibXML::_cleanup_callbacks at line 491 | |||
| 1900 | 5 | 16µs | 3µs | my $self = shift; |
| 1901 | ||||
| 1902 | $_CUR_CB = undef; | |||
| 1903 | @_GLOBAL_CALLBACKS = (); | |||
| 1904 | @_CB_STACK = (); | |||
| 1905 | ||||
| 1906 | $self->lib_cleanup_callbacks(); # spent 11µs making 1 call to XML::LibXML::InputCallback::lib_cleanup_callbacks | |||
| 1907 | } | |||
| 1908 | ||||
| 1909 | 1 | 400ns | 400ns | $XML::LibXML::__loaded=1; |
| 1910 | ||||
| 1911 | 1 | 26µs | 26µs | 1; |
| 1912 | ||||
| 1913 | __END__ | |||
# spent 11µs within XML::LibXML::InputCallback::lib_cleanup_callbacks which was called
# once (11µs+0s) by XML::LibXML::InputCallback::cleanup_callbacks at line 1906 of /usr/local/lib/perl/5.10.0/XML/LibXML.pm | ||||
# spent 28µs within XML::LibXML::InputCallback::lib_init_callbacks which was called
# once (28µs+0s) by XML::LibXML::InputCallback::init_callbacks at line 1895 of /usr/local/lib/perl/5.10.0/XML/LibXML.pm | ||||
# spent 34µs within XML::LibXML::LIBXML_RUNTIME_VERSION which was called
# once (34µs+0s) at line 169 of /usr/local/lib/perl/5.10.0/XML/LibXML.pm | ||||
# spent 12µs within XML::LibXML::LIBXML_VERSION which was called
# once (12µs+0s) at line 170 of /usr/local/lib/perl/5.10.0/XML/LibXML.pm | ||||
# spent 12.5ms (4.19+8.29) within XML::LibXML::_parse_sax_file which was called
# once (4.19ms+8.29ms) by XML::LibXML::parse_file at line 635 of /usr/local/lib/perl/5.10.0/XML/LibXML.pm | ||||
# spent 1.06ms within XML::LibXML::bootstrap which was called
# once (1.06ms+0s) by DynaLoader::bootstrap at line 219 of /usr/lib/perl/5.10/DynaLoader.pm |