| 1 | # $Id: /tree-xpathengine/trunk/lib/Tree/XPathEngine/LocationPath.pm 22 2006-02-13T14:00:25.731780Z mrodrigu $ | ||||||||||
| 2 | |||||||||||
| 3 | package Tree::XPathEngine::LocationPath; | ||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 155 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 7 | 155 | my $class = shift; | |||||||||
| 8 | 155 | my $self = []; | |||||||||
| 9 | 155 | bless $self, $class; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 13 | 0 | my $self = shift; | |||||||||
| 14 | 0 | my $string; | |||||||||
| 15 | 0 | ▶ | for (my $i = 0; $i < @$self; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | $string .= $self->[$i]->as_string; | |||||||||
| 17 | 0 | ▶ | $string .= "/" if $self->[$i+1]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | } | ||||||||||
| 19 | 0 | return $string; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub as_xml { | ||||||||
|
Subroutine
as_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 23 | 0 | my $self = shift; | |||||||||
| 24 | 0 | my $string = "<LocationPath>\n"; | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | for (my $i = 0; $i < @$self; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | $string .= $self->[$i]->as_xml; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | $string .= "</LocationPath>\n"; | |||||||||
| 31 | 0 | return $string; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 640 | ▶ | sub evaluate { | ||||||||
|
Subroutine
evaluate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 36 | 640 | my $self = shift; | |||||||||
| 37 | # context _MUST_ be a single node | ||||||||||
| 38 | 640 | my $context = shift; | |||||||||
| 39 | 640 | ▶ | die "No context" unless $context; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | # I _think_ this is how it should work :) | ||||||||||
| 42 | |||||||||||
| 43 | 640 | my $nodeset = Tree::XPathEngine::NodeSet->new(); | |||||||||
| 44 | 640 | $nodeset->push($context); | |||||||||
| 45 | |||||||||||
| 46 | 640 | foreach my $step (@$self) { | |||||||||
| 47 | # For each step | ||||||||||
| 48 | # evaluate the step with the nodeset | ||||||||||
| 49 | 904 | my $pos = 1; | |||||||||
| 50 | 904 | $nodeset = $step->evaluate($nodeset); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 638 | return $nodeset->remove_duplicates; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 6 | 1; | |||||||||
| 57 | |||||||||||
| 58 | __END__ | ||||||||||