XPath/LocationPath.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« XPath/Node/PI.pm ↑ Summary XPath/Step.pm »
1 package XML::XPath::LocationPath;
2  
3 $VERSION = '1.26';
4  
5 1 ▶use XML::XPath::Root;
Subroutine BEGIN: called CC=1 SCAR=2.6
6 use strict; use warnings;
7  
8 sub new {
9 my $class = shift;
10 my $self = [];
11 bless $self, $class;
12 }
13  
14 sub as_string {
15 my $self = shift;
16 my $string;
17 for (my $i = 0; $i < @$self; $i++) {
18 $string .= $self->[$i]->as_string if defined $self->[$i]->as_string;
19 $string .= "/" if $self->[$i+1];
20 }
21 return $string;
22 }
23  
24 sub as_xml {
25 my $self = shift;
26 my $string = "<LocationPath>\n";
27  
28 for (my $i = 0; $i < @$self; $i++) {
29 $string .= $self->[$i]->as_xml;
30 }
31  
32 $string .= "</LocationPath>\n";
33 return $string;
34 }
35  
36 sub set_root {
37 my $self = shift;
38 unshift @$self, XML::XPath::Root->new();
39 }
40  
41 sub evaluate {
42 my $self = shift;
43 # context _MUST_ be a single node
44 my $context = shift;
45 die "No context" unless $context;
46  
47 # I _think_ this is how it should work :)
48  
49 my $nodeset = XML::XPath::NodeSet->new();
50 $nodeset->push($context);
51  
52 foreach my $step (@$self) {
53 # For each step
54 # evaluate the step with the nodeset
55 my $pos = 1;
56 $nodeset = $step->evaluate($nodeset);
57 }
58  
59 return $nodeset->remove_duplicates;
60 }
61  
62 1;
« XPath/Node/PI.pm ↑ Summary XPath/Step.pm »