line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Parser::Lite::Tree::XPath; |
2
|
|
|
|
|
|
|
|
3
|
29
|
|
|
29
|
|
34041
|
use strict; |
|
29
|
|
|
|
|
74
|
|
|
29
|
|
|
|
|
1201
|
|
4
|
29
|
|
|
29
|
|
18219
|
use XML::Parser::Lite::Tree::XPath::Tokener; |
|
29
|
|
|
|
|
97
|
|
|
29
|
|
|
|
|
1239
|
|
5
|
29
|
|
|
29
|
|
20833
|
use XML::Parser::Lite::Tree::XPath::Tree; |
|
29
|
|
|
|
|
98
|
|
|
29
|
|
|
|
|
1420
|
|
6
|
29
|
|
|
29
|
|
25693
|
use XML::Parser::Lite::Tree::XPath::Eval; |
|
29
|
|
|
|
|
77
|
|
|
29
|
|
|
|
|
9876
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.24'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
29
|
|
|
29
|
1
|
79
|
my $class = shift; |
12
|
29
|
|
|
|
|
109
|
my $self = bless {}, $class; |
13
|
29
|
|
|
|
|
199
|
$self->{tree} = shift; |
14
|
29
|
|
|
|
|
96
|
$self->{error} = 0; |
15
|
|
|
|
|
|
|
|
16
|
29
|
|
|
|
|
118
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub query { |
20
|
130
|
|
|
130
|
1
|
239
|
my ($self, $xpath) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# toke the xpath |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
|
26
|
130
|
|
|
|
|
839
|
my $tokener = XML::Parser::Lite::Tree::XPath::Tokener->new(); |
27
|
|
|
|
|
|
|
|
28
|
130
|
50
|
|
|
|
515
|
unless ($tokener->parse($xpath)){ |
29
|
0
|
|
|
|
|
0
|
$self->{error} = $tokener->{error}; |
30
|
0
|
|
|
|
|
0
|
return 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# tree the xpath |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
|
38
|
130
|
|
|
|
|
1697
|
my $xtree = XML::Parser::Lite::Tree::XPath::Tree->new(); |
39
|
|
|
|
|
|
|
|
40
|
130
|
50
|
|
|
|
549
|
unless ($xtree->build_tree($tokener->{tokens})){ |
41
|
0
|
|
|
|
|
0
|
$self->{error} = $xtree->{error}; |
42
|
0
|
|
|
|
|
0
|
return 0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# eval |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
|
50
|
130
|
|
|
|
|
799
|
my $eval = XML::Parser::Lite::Tree::XPath::Eval->new(); |
51
|
|
|
|
|
|
|
|
52
|
130
|
|
|
|
|
847
|
my $out = $eval->query($xtree, $self->{tree}); |
53
|
|
|
|
|
|
|
|
54
|
130
|
|
|
|
|
302
|
$self->{error} = $eval->{error}; |
55
|
|
|
|
|
|
|
|
56
|
130
|
|
|
|
|
2000
|
return $out; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub select_nodes { |
60
|
73
|
|
|
73
|
1
|
141
|
my ($self, $xpath) = @_; |
61
|
|
|
|
|
|
|
|
62
|
73
|
|
|
|
|
246
|
my $out = $self->query($xpath); |
63
|
|
|
|
|
|
|
|
64
|
73
|
50
|
|
|
|
259
|
return 0 unless $out; |
65
|
|
|
|
|
|
|
|
66
|
73
|
50
|
|
|
|
295
|
if ($out->{type} ne 'nodeset'){ |
67
|
0
|
|
|
|
|
0
|
$self->{error} = "Result was not a nodeset (was a $out->{type})"; |
68
|
0
|
|
|
|
|
0
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
73
|
|
|
|
|
391
|
return $out->{value}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |