Filename | /usr/lib/x86_64-linux-gnu/perl5/5.20/XML/LibXML/XPathContext.pm |
Statements | Executed 17 statements in 879µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 22µs | BEGIN@12 | XML::LibXML::XPathContext::
1 | 1 | 1 | 8µs | 18µs | BEGIN@142 | XML::LibXML::XPathContext::
1 | 1 | 1 | 7µs | 7µs | BEGIN@17 | XML::LibXML::XPathContext::
1 | 1 | 1 | 7µs | 34µs | BEGIN@16 | XML::LibXML::XPathContext::
1 | 1 | 1 | 7µs | 10µs | BEGIN@13 | XML::LibXML::XPathContext::
1 | 1 | 1 | 6µs | 38µs | BEGIN@14 | XML::LibXML::XPathContext::
1 | 1 | 1 | 4µs | 4µs | BEGIN@18 | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | CLONE_SKIP | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | _guarded_find_call | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | _perl_dispatcher | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | exists | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | find | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | findnodes | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | findvalue | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | registerFunction | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | unregisterFunction | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | unregisterFunctionNS | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | unregisterNs | XML::LibXML::XPathContext::
0 | 0 | 0 | 0s | 0s | unregisterVarLookupFunc | XML::LibXML::XPathContext::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id: XPathContext.pm 422 2002-11-08 17:10:30Z phish $ | ||||
2 | # | ||||
3 | # This is free software, you may use it and distribute it under the same terms as | ||||
4 | # Perl itself. | ||||
5 | # | ||||
6 | # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas | ||||
7 | # | ||||
8 | # | ||||
9 | |||||
10 | package XML::LibXML::XPathContext; | ||||
11 | |||||
12 | 2 | 22µs | 2 | 33µs | # spent 22µs (12+11) within XML::LibXML::XPathContext::BEGIN@12 which was called:
# once (12µs+11µs) by XML::LibXML::BEGIN@28 at line 12 # spent 22µs making 1 call to XML::LibXML::XPathContext::BEGIN@12
# spent 11µs making 1 call to strict::import |
13 | 2 | 22µs | 2 | 14µs | # spent 10µs (7+4) within XML::LibXML::XPathContext::BEGIN@13 which was called:
# once (7µs+4µs) by XML::LibXML::BEGIN@28 at line 13 # spent 10µs making 1 call to XML::LibXML::XPathContext::BEGIN@13
# spent 4µs making 1 call to warnings::import |
14 | 2 | 21µs | 2 | 70µs | # spent 38µs (6+32) within XML::LibXML::XPathContext::BEGIN@14 which was called:
# once (6µs+32µs) by XML::LibXML::BEGIN@28 at line 14 # spent 38µs making 1 call to XML::LibXML::XPathContext::BEGIN@14
# spent 32µs making 1 call to vars::import |
15 | |||||
16 | 2 | 21µs | 2 | 61µs | # spent 34µs (7+27) within XML::LibXML::XPathContext::BEGIN@16 which was called:
# once (7µs+27µs) by XML::LibXML::BEGIN@28 at line 16 # spent 34µs making 1 call to XML::LibXML::XPathContext::BEGIN@16
# spent 27µs making 1 call to Exporter::import |
17 | 2 | 28µs | 1 | 7µs | # spent 7µs within XML::LibXML::XPathContext::BEGIN@17 which was called:
# once (7µs+0s) by XML::LibXML::BEGIN@28 at line 17 # spent 7µs making 1 call to XML::LibXML::XPathContext::BEGIN@17 |
18 | 2 | 715µs | 1 | 4µs | # spent 4µs within XML::LibXML::XPathContext::BEGIN@18 which was called:
# once (4µs+0s) by XML::LibXML::BEGIN@28 at line 18 # spent 4µs making 1 call to XML::LibXML::XPathContext::BEGIN@18 |
19 | |||||
20 | 1 | 400ns | $VERSION = "2.0116"; # VERSION TEMPLATE: DO NOT CHANGE | ||
21 | |||||
22 | # should LibXML XPath data types be used for simple objects | ||||
23 | # when passing parameters to extension functions (default: no) | ||||
24 | 1 | 100ns | $USE_LIBXML_DATA_TYPES = 0; | ||
25 | |||||
26 | sub CLONE_SKIP { 1 } | ||||
27 | |||||
28 | sub findnodes { | ||||
29 | my ($self, $xpath, $node) = @_; | ||||
30 | |||||
31 | my @nodes = $self->_guarded_find_call('_findnodes', $node, $xpath); | ||||
32 | |||||
33 | if (wantarray) { | ||||
34 | return @nodes; | ||||
35 | } | ||||
36 | else { | ||||
37 | return XML::LibXML::NodeList->new(@nodes); | ||||
38 | } | ||||
39 | } | ||||
40 | |||||
41 | sub find { | ||||
42 | my ($self, $xpath, $node) = @_; | ||||
43 | |||||
44 | my ($type, @params) = $self->_guarded_find_call('_find', $node, $xpath,0); | ||||
45 | |||||
46 | if ($type) { | ||||
47 | return $type->new(@params); | ||||
48 | } | ||||
49 | return undef; | ||||
50 | } | ||||
51 | |||||
52 | sub exists { | ||||
53 | my ($self, $xpath, $node) = @_; | ||||
54 | my (undef, $value) = $self->_guarded_find_call('_find', $node, $xpath,1); | ||||
55 | return $value; | ||||
56 | } | ||||
57 | |||||
58 | sub findvalue { | ||||
59 | my $self = shift; | ||||
60 | return $self->find(@_)->to_literal->value; | ||||
61 | } | ||||
62 | |||||
63 | sub _guarded_find_call { | ||||
64 | my ($self, $method, $node)=(shift,shift,shift); | ||||
65 | |||||
66 | my $prev_node; | ||||
67 | if (ref($node)) { | ||||
68 | $prev_node = $self->getContextNode(); | ||||
69 | $self->setContextNode($node); | ||||
70 | } | ||||
71 | my @ret; | ||||
72 | eval { | ||||
73 | @ret = $self->$method(@_); | ||||
74 | }; | ||||
75 | $self->_free_node_pool; | ||||
76 | $self->setContextNode($prev_node) if ref($node); | ||||
77 | |||||
78 | if ($@) { | ||||
79 | my $err = $@; | ||||
80 | chomp $err; | ||||
81 | croak $err; | ||||
82 | } | ||||
83 | |||||
84 | return @ret; | ||||
85 | } | ||||
86 | |||||
87 | sub registerFunction { | ||||
88 | my ($self, $name, $sub) = @_; | ||||
89 | $self->registerFunctionNS($name, undef, $sub); | ||||
90 | return; | ||||
91 | } | ||||
92 | |||||
93 | sub unregisterNs { | ||||
94 | my ($self, $prefix) = @_; | ||||
95 | $self->registerNs($prefix, undef); | ||||
96 | return; | ||||
97 | } | ||||
98 | |||||
99 | sub unregisterFunction { | ||||
100 | my ($self, $name) = @_; | ||||
101 | $self->registerFunctionNS($name, undef, undef); | ||||
102 | return; | ||||
103 | } | ||||
104 | |||||
105 | sub unregisterFunctionNS { | ||||
106 | my ($self, $name, $ns) = @_; | ||||
107 | $self->registerFunctionNS($name, $ns, undef); | ||||
108 | return; | ||||
109 | } | ||||
110 | |||||
111 | sub unregisterVarLookupFunc { | ||||
112 | my ($self) = @_; | ||||
113 | $self->registerVarLookupFunc(undef, undef); | ||||
114 | return; | ||||
115 | } | ||||
116 | |||||
117 | # extension function perl dispatcher | ||||
118 | # borrowed from XML::LibXSLT | ||||
119 | |||||
120 | sub _perl_dispatcher { | ||||
121 | my $func = shift; | ||||
122 | my @params = @_; | ||||
123 | my @perlParams; | ||||
124 | |||||
125 | my $i = 0; | ||||
126 | while (@params) { | ||||
127 | my $type = shift(@params); | ||||
128 | if ($type eq 'XML::LibXML::Literal' or | ||||
129 | $type eq 'XML::LibXML::Number' or | ||||
130 | $type eq 'XML::LibXML::Boolean') | ||||
131 | { | ||||
132 | my $val = shift(@params); | ||||
133 | unshift(@perlParams, $USE_LIBXML_DATA_TYPES ? $type->new($val) : $val); | ||||
134 | } | ||||
135 | elsif ($type eq 'XML::LibXML::NodeList') { | ||||
136 | my $node_count = shift(@params); | ||||
137 | unshift(@perlParams, $type->new(splice(@params, 0, $node_count))); | ||||
138 | } | ||||
139 | } | ||||
140 | |||||
141 | $func = "main::$func" unless ref($func) || $func =~ /(.+)::/; | ||||
142 | 2 | 48µs | 2 | 28µs | # spent 18µs (8+10) within XML::LibXML::XPathContext::BEGIN@142 which was called:
# once (8µs+10µs) by XML::LibXML::BEGIN@28 at line 142 # spent 18µs making 1 call to XML::LibXML::XPathContext::BEGIN@142
# spent 10µs making 1 call to strict::unimport |
143 | my $res = $func->(@perlParams); | ||||
144 | return $res; | ||||
145 | } | ||||
146 | |||||
147 | 1 | 2µs | 1; |