← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:10 2010

File /usr/lib/perl5/XML/LibXML/XPathContext.pm
Statements Executed 21
Total Time 0.0008571 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sXML::LibXML::XPathContext::::BEGINXML::LibXML::XPathContext::BEGIN
0000s0sXML::LibXML::XPathContext::::_guarded_find_callXML::LibXML::XPathContext::_guarded_find_call
0000s0sXML::LibXML::XPathContext::::_perl_dispatcherXML::LibXML::XPathContext::_perl_dispatcher
0000s0sXML::LibXML::XPathContext::::findXML::LibXML::XPathContext::find
0000s0sXML::LibXML::XPathContext::::findnodesXML::LibXML::XPathContext::findnodes
0000s0sXML::LibXML::XPathContext::::findvalueXML::LibXML::XPathContext::findvalue
0000s0sXML::LibXML::XPathContext::::registerFunctionXML::LibXML::XPathContext::registerFunction
0000s0sXML::LibXML::XPathContext::::unregisterFunctionXML::LibXML::XPathContext::unregisterFunction
0000s0sXML::LibXML::XPathContext::::unregisterFunctionNSXML::LibXML::XPathContext::unregisterFunctionNS
0000s0sXML::LibXML::XPathContext::::unregisterNsXML::LibXML::XPathContext::unregisterNs
0000s0sXML::LibXML::XPathContext::::unregisterVarLookupFuncXML::LibXML::XPathContext::unregisterVarLookupFunc
LineStmts.Exclusive
Time
Avg.Code
1# $Id: XPathContext.pm 422 2002-11-08 17:10:30Z phish $
2
3package XML::LibXML::XPathContext;
4
5333µs11µsuse strict;
# spent 13µs making 1 call to strict::import
6328µs9µsuse vars qw($VERSION @ISA $USE_LIBXML_DATA_TYPES);
# spent 62µs making 1 call to vars::import
7
8324µs8µsuse Carp;
# spent 61µs making 1 call to Exporter::import
9331µs10µsuse XML::LibXML;
# spent 5µs making 1 call to import
103665µs222µsuse XML::LibXML::NodeList;
# spent 8µs making 1 call to import
11
121700ns700ns$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)
161400ns400ns$USE_LIBXML_DATA_TYPES = 0;
17
18sub 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
31sub 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
42sub findvalue {
43 my $self = shift;
44 return $self->find(@_)->to_literal->value;
45}
46
47sub _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
71sub registerFunction {
72 my ($self, $name, $sub) = @_;
73 $self->registerFunctionNS($name, undef, $sub);
74 return;
75}
76
77sub unregisterNs {
78 my ($self, $prefix) = @_;
79 $self->registerNs($prefix, undef);
80 return;
81}
82
83sub unregisterFunction {
84 my ($self, $name) = @_;
85 $self->registerFunctionNS($name, undef, undef);
86 return;
87}
88
89sub unregisterFunctionNS {
90 my ($self, $name, $ns) = @_;
91 $self->registerFunctionNS($name, $ns, undef);
92 return;
93}
94
95sub unregisterVarLookupFunc {
96 my ($self) = @_;
97 $self->registerVarLookupFunc(undef, undef);
98 return;
99}
100
101# extension function perl dispatcher
102# borrowed from XML::LibXSLT
103
104sub _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 =~ /(.+)::/;
126369µs23µs no strict 'refs';
# spent 26µs making 1 call to strict::unimport
127 my $res = $func->(@perlParams);
128 return $res;
129}
130
13114µs4µs1;