| 1 | package XML::Parser::Lite::Tree::XPath; | ||||||||||
| 2 | |||||||||||
| 3 | 29 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 29 | ▶ | use XML::Parser::Lite::Tree::XPath::Tokener; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 29 | ▶ | use XML::Parser::Lite::Tree::XPath::Tree; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 29 | ▶ | use XML::Parser::Lite::Tree::XPath::Eval; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 29 | our $VERSION = '0.24'; | |||||||||
| 9 | |||||||||||
| 10 | 29 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 11 | 29 | my $class = shift; | |||||||||
| 12 | 29 | my $self = bless {}, $class; | |||||||||
| 13 | 29 | $self->{tree} = shift; | |||||||||
| 14 | 29 | $self->{error} = 0; | |||||||||
| 15 | |||||||||||
| 16 | 29 | return $self; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 130 | ▶ | sub query { | ||||||||
|
Subroutine
query: called CC=3 SCAR=12.2
Pod
documented
| |||||||||||
| 20 | 130 | my ($self, $xpath) = @_; | |||||||||
| 21 | |||||||||||
| 22 | # | ||||||||||
| 23 | # toke the xpath | ||||||||||
| 24 | # | ||||||||||
| 25 | |||||||||||
| 26 | 130 | my $tokener = XML::Parser::Lite::Tree::XPath::Tokener->new(); | |||||||||
| 27 | |||||||||||
| 28 | 130 | ▶ | unless ($tokener->parse($xpath)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $self->{error} = $tokener->{error}; | |||||||||
| 30 | 0 | return 0; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | # | ||||||||||
| 35 | # tree the xpath | ||||||||||
| 36 | # | ||||||||||
| 37 | |||||||||||
| 38 | 130 | my $xtree = XML::Parser::Lite::Tree::XPath::Tree->new(); | |||||||||
| 39 | |||||||||||
| 40 | 130 | ▶ | unless ($xtree->build_tree($tokener->{tokens})){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | $self->{error} = $xtree->{error}; | |||||||||
| 42 | 0 | return 0; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | # | ||||||||||
| 47 | # eval | ||||||||||
| 48 | # | ||||||||||
| 49 | |||||||||||
| 50 | 130 | my $eval = XML::Parser::Lite::Tree::XPath::Eval->new(); | |||||||||
| 51 | |||||||||||
| 52 | 130 | my $out = $eval->query($xtree, $self->{tree}); | |||||||||
| 53 | |||||||||||
| 54 | 130 | $self->{error} = $eval->{error}; | |||||||||
| 55 | |||||||||||
| 56 | 130 | return $out; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 73 | ▶ | sub select_nodes { | ||||||||
|
Subroutine
select_nodes: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||
| 60 | 73 | my ($self, $xpath) = @_; | |||||||||
| 61 | |||||||||||
| 62 | 73 | my $out = $self->query($xpath); | |||||||||
| 63 | |||||||||||
| 64 | 73 | ▶ | return 0 unless $out; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 73 | ▶ | if ($out->{type} ne 'nodeset'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $self->{error} = "Result was not a nodeset (was a $out->{type})"; | |||||||||
| 68 | 0 | return 0; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 73 | return $out->{value}; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 29 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||