line |
stmt |
bran |
cond |
sub |
pod |
time |
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
|
67
|
|
|
67
|
|
399
|
use strict; |
|
67
|
|
|
|
|
115
|
|
|
67
|
|
|
|
|
1784
|
|
13
|
67
|
|
|
67
|
|
280
|
use warnings; |
|
67
|
|
|
|
|
114
|
|
|
67
|
|
|
|
|
1839
|
|
14
|
67
|
|
|
67
|
|
310
|
use vars qw($VERSION @ISA $USE_LIBXML_DATA_TYPES); |
|
67
|
|
|
|
|
121
|
|
|
67
|
|
|
|
|
3450
|
|
15
|
|
|
|
|
|
|
|
16
|
67
|
|
|
67
|
|
365
|
use Carp; |
|
67
|
|
|
|
|
119
|
|
|
67
|
|
|
|
|
4299
|
|
17
|
67
|
|
|
67
|
|
394
|
use XML::LibXML; |
|
67
|
|
|
|
|
125
|
|
|
67
|
|
|
|
|
1899
|
|
18
|
67
|
|
|
67
|
|
335
|
use XML::LibXML::NodeList; |
|
67
|
|
|
|
|
111
|
|
|
67
|
|
|
|
|
45203
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = "2.0208"; # 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
|
|
|
|
|
|
|
$USE_LIBXML_DATA_TYPES = 0; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
|
0
|
sub CLONE_SKIP { 1 } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub findnodes { |
29
|
61
|
|
|
61
|
1
|
4705
|
my ($self, $xpath, $node) = @_; |
30
|
|
|
|
|
|
|
|
31
|
61
|
|
|
|
|
116
|
my @nodes = $self->_guarded_find_call('_findnodes', $node, $xpath); |
32
|
|
|
|
|
|
|
|
33
|
59
|
100
|
|
|
|
127
|
if (wantarray) { |
34
|
13
|
|
|
|
|
160
|
return @nodes; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
46
|
|
|
|
|
129
|
return XML::LibXML::NodeList->new(@nodes); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub find { |
42
|
66
|
|
|
66
|
1
|
3828
|
my ($self, $xpath, $node) = @_; |
43
|
|
|
|
|
|
|
|
44
|
66
|
|
|
|
|
130
|
my ($type, @params) = $self->_guarded_find_call('_find', $node, $xpath,0); |
45
|
|
|
|
|
|
|
|
46
|
56
|
50
|
|
|
|
136
|
if ($type) { |
47
|
56
|
|
|
|
|
226
|
return $type->new(@params); |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
0
|
return undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub exists { |
53
|
3
|
|
|
3
|
1
|
11
|
my ($self, $xpath, $node) = @_; |
54
|
3
|
|
|
|
|
7
|
my (undef, $value) = $self->_guarded_find_call('_find', $node, $xpath,1); |
55
|
3
|
|
|
|
|
12
|
return $value; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub findvalue { |
59
|
44
|
|
|
44
|
1
|
5069
|
my $self = shift; |
60
|
44
|
|
|
|
|
92
|
return $self->find(@_)->to_literal->value; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _guarded_find_call { |
64
|
130
|
|
|
130
|
|
211
|
my ($self, $method, $node)=(shift,shift,shift); |
65
|
|
|
|
|
|
|
|
66
|
130
|
|
|
|
|
152
|
my $prev_node; |
67
|
130
|
100
|
|
|
|
246
|
if (ref($node)) { |
68
|
17
|
|
|
|
|
40
|
$prev_node = $self->getContextNode(); |
69
|
17
|
|
|
|
|
50
|
$self->setContextNode($node); |
70
|
|
|
|
|
|
|
} |
71
|
130
|
|
|
|
|
175
|
my @ret; |
72
|
130
|
|
|
|
|
174
|
eval { |
73
|
130
|
|
|
|
|
2885
|
@ret = $self->$method(@_); |
74
|
|
|
|
|
|
|
}; |
75
|
130
|
|
|
|
|
644
|
$self->_free_node_pool; |
76
|
130
|
100
|
|
|
|
253
|
$self->setContextNode($prev_node) if ref($node); |
77
|
|
|
|
|
|
|
|
78
|
130
|
100
|
|
|
|
225
|
if ($@) { |
79
|
12
|
|
|
|
|
17
|
my $err = $@; |
80
|
12
|
|
|
|
|
24
|
chomp $err; |
81
|
12
|
|
|
|
|
1107
|
croak $err; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
118
|
|
|
|
|
743
|
return @ret; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub registerFunction { |
88
|
10
|
|
|
10
|
1
|
1676
|
my ($self, $name, $sub) = @_; |
89
|
10
|
|
|
|
|
65
|
$self->registerFunctionNS($name, undef, $sub); |
90
|
10
|
|
|
|
|
20
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub unregisterNs { |
94
|
3
|
|
|
3
|
1
|
8
|
my ($self, $prefix) = @_; |
95
|
3
|
|
|
|
|
15
|
$self->registerNs($prefix, undef); |
96
|
3
|
|
|
|
|
6
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub unregisterFunction { |
100
|
2
|
|
|
2
|
1
|
6
|
my ($self, $name) = @_; |
101
|
2
|
|
|
|
|
18
|
$self->registerFunctionNS($name, undef, undef); |
102
|
2
|
|
|
|
|
5
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub unregisterFunctionNS { |
106
|
1
|
|
|
1
|
1
|
4
|
my ($self, $name, $ns) = @_; |
107
|
1
|
|
|
|
|
10
|
$self->registerFunctionNS($name, $ns, undef); |
108
|
1
|
|
|
|
|
3
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub unregisterVarLookupFunc { |
112
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
113
|
1
|
|
|
|
|
6
|
$self->registerVarLookupFunc(undef, undef); |
114
|
1
|
|
|
|
|
2
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# extension function perl dispatcher |
118
|
|
|
|
|
|
|
# borrowed from XML::LibXSLT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _perl_dispatcher { |
121
|
32
|
|
|
32
|
|
66
|
my $func = shift; |
122
|
32
|
|
|
|
|
188
|
my @params = @_; |
123
|
32
|
|
|
|
|
38
|
my @perlParams; |
124
|
|
|
|
|
|
|
|
125
|
32
|
|
|
|
|
34
|
my $i = 0; |
126
|
32
|
|
|
|
|
61
|
while (@params) { |
127
|
23
|
|
|
|
|
39
|
my $type = shift(@params); |
128
|
23
|
100
|
100
|
|
|
90
|
if ($type eq 'XML::LibXML::Literal' or |
|
|
50
|
66
|
|
|
|
|
129
|
|
|
|
|
|
|
$type eq 'XML::LibXML::Number' or |
130
|
|
|
|
|
|
|
$type eq 'XML::LibXML::Boolean') |
131
|
|
|
|
|
|
|
{ |
132
|
12
|
|
|
|
|
16
|
my $val = shift(@params); |
133
|
12
|
50
|
|
|
|
31
|
unshift(@perlParams, $USE_LIBXML_DATA_TYPES ? $type->new($val) : $val); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
elsif ($type eq 'XML::LibXML::NodeList') { |
136
|
11
|
|
|
|
|
15
|
my $node_count = shift(@params); |
137
|
11
|
|
|
|
|
91
|
unshift(@perlParams, $type->new(splice(@params, 0, $node_count))); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
32
|
100
|
66
|
|
|
76
|
$func = "main::$func" unless ref($func) || $func =~ /(.+)::/; |
142
|
67
|
|
|
67
|
|
482
|
no strict 'refs'; |
|
67
|
|
|
|
|
166
|
|
|
67
|
|
|
|
|
4589
|
|
143
|
32
|
|
|
|
|
61
|
my $res = $func->(@perlParams); |
144
|
31
|
|
|
|
|
14737
|
return $res; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |