| File | /usr/lib/perl5/XML/LibXML/XPathContext.pm |
| Statements Executed | 21 |
| Total Time | 0.0008571 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::BEGIN |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::_guarded_find_call |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::_perl_dispatcher |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::find |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::findnodes |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::findvalue |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::registerFunction |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::unregisterFunction |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::unregisterFunctionNS |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::unregisterNs |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::XPathContext::unregisterVarLookupFunc |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | # $Id: XPathContext.pm 422 2002-11-08 17:10:30Z phish $ | |||
| 2 | ||||
| 3 | package XML::LibXML::XPathContext; | |||
| 4 | ||||
| 5 | 3 | 33µs | 11µs | use strict; # spent 13µs making 1 call to strict::import |
| 6 | 3 | 28µs | 9µs | use vars qw($VERSION @ISA $USE_LIBXML_DATA_TYPES); # spent 62µs making 1 call to vars::import |
| 7 | ||||
| 8 | 3 | 24µs | 8µs | use Carp; # spent 61µs making 1 call to Exporter::import |
| 9 | 3 | 31µs | 10µs | use XML::LibXML; # spent 5µs making 1 call to import |
| 10 | 3 | 665µs | 222µs | use XML::LibXML::NodeList; # spent 8µs making 1 call to import |
| 11 | ||||
| 12 | 1 | 700ns | 700ns | $VERSION = "1.66"; # VERSION TEMPLATE: DO NOT CHANGE |
| 13 | ||||
| 14 | # should LibXML XPath data types be used for simple objects | |||
| 15 | # when passing parameters to extension functions (default: no) | |||
| 16 | 1 | 400ns | 400ns | $USE_LIBXML_DATA_TYPES = 0; |
| 17 | ||||
| 18 | sub findnodes { | |||
| 19 | my ($self, $xpath, $node) = @_; | |||
| 20 | ||||
| 21 | my @nodes = $self->_guarded_find_call('_findnodes', $xpath, $node); | |||
| 22 | ||||
| 23 | if (wantarray) { | |||
| 24 | return @nodes; | |||
| 25 | } | |||
| 26 | else { | |||
| 27 | return XML::LibXML::NodeList->new(@nodes); | |||
| 28 | } | |||
| 29 | } | |||
| 30 | ||||
| 31 | sub find { | |||
| 32 | my ($self, $xpath, $node) = @_; | |||
| 33 | ||||
| 34 | my ($type, @params) = $self->_guarded_find_call('_find', $xpath, $node); | |||
| 35 | ||||
| 36 | if ($type) { | |||
| 37 | return $type->new(@params); | |||
| 38 | } | |||
| 39 | return undef; | |||
| 40 | } | |||
| 41 | ||||
| 42 | sub findvalue { | |||
| 43 | my $self = shift; | |||
| 44 | return $self->find(@_)->to_literal->value; | |||
| 45 | } | |||
| 46 | ||||
| 47 | sub _guarded_find_call { | |||
| 48 | my ($self, $method, $xpath, $node) = @_; | |||
| 49 | ||||
| 50 | my $prev_node; | |||
| 51 | if (ref($node)) { | |||
| 52 | $prev_node = $self->getContextNode(); | |||
| 53 | $self->setContextNode($node); | |||
| 54 | } | |||
| 55 | my @ret; | |||
| 56 | eval { | |||
| 57 | @ret = $self->$method($xpath); | |||
| 58 | }; | |||
| 59 | $self->_free_node_pool; | |||
| 60 | $self->setContextNode($prev_node) if ref($node); | |||
| 61 | ||||
| 62 | if ($@) { | |||
| 63 | my $err = $@; | |||
| 64 | chomp $err; | |||
| 65 | croak $err; | |||
| 66 | } | |||
| 67 | ||||
| 68 | return @ret; | |||
| 69 | } | |||
| 70 | ||||
| 71 | sub registerFunction { | |||
| 72 | my ($self, $name, $sub) = @_; | |||
| 73 | $self->registerFunctionNS($name, undef, $sub); | |||
| 74 | return; | |||
| 75 | } | |||
| 76 | ||||
| 77 | sub unregisterNs { | |||
| 78 | my ($self, $prefix) = @_; | |||
| 79 | $self->registerNs($prefix, undef); | |||
| 80 | return; | |||
| 81 | } | |||
| 82 | ||||
| 83 | sub unregisterFunction { | |||
| 84 | my ($self, $name) = @_; | |||
| 85 | $self->registerFunctionNS($name, undef, undef); | |||
| 86 | return; | |||
| 87 | } | |||
| 88 | ||||
| 89 | sub unregisterFunctionNS { | |||
| 90 | my ($self, $name, $ns) = @_; | |||
| 91 | $self->registerFunctionNS($name, $ns, undef); | |||
| 92 | return; | |||
| 93 | } | |||
| 94 | ||||
| 95 | sub unregisterVarLookupFunc { | |||
| 96 | my ($self) = @_; | |||
| 97 | $self->registerVarLookupFunc(undef, undef); | |||
| 98 | return; | |||
| 99 | } | |||
| 100 | ||||
| 101 | # extension function perl dispatcher | |||
| 102 | # borrowed from XML::LibXSLT | |||
| 103 | ||||
| 104 | sub _perl_dispatcher { | |||
| 105 | my $func = shift; | |||
| 106 | my @params = @_; | |||
| 107 | my @perlParams; | |||
| 108 | ||||
| 109 | my $i = 0; | |||
| 110 | while (@params) { | |||
| 111 | my $type = shift(@params); | |||
| 112 | if ($type eq 'XML::LibXML::Literal' or | |||
| 113 | $type eq 'XML::LibXML::Number' or | |||
| 114 | $type eq 'XML::LibXML::Boolean') | |||
| 115 | { | |||
| 116 | my $val = shift(@params); | |||
| 117 | unshift(@perlParams, $USE_LIBXML_DATA_TYPES ? $type->new($val) : $val); | |||
| 118 | } | |||
| 119 | elsif ($type eq 'XML::LibXML::NodeList') { | |||
| 120 | my $node_count = shift(@params); | |||
| 121 | unshift(@perlParams, $type->new(splice(@params, 0, $node_count))); | |||
| 122 | } | |||
| 123 | } | |||
| 124 | ||||
| 125 | $func = "main::$func" unless ref($func) || $func =~ /(.+)::/; | |||
| 126 | 3 | 69µs | 23µs | no strict 'refs'; # spent 26µs making 1 call to strict::unimport |
| 127 | my $res = $func->(@perlParams); | |||
| 128 | return $res; | |||
| 129 | } | |||
| 130 | ||||
| 131 | 1 | 4µs | 4µs | 1; |