blib/lib/PPIx/XPath.pm

filter: Statementstmt 83.1% 222 / 267 Branchbran 67.3% 35 / 52 Conditioncond 38.1% 16 / 42 MC/DCmcdc 14.2% 3 / 21 Subroutinesub 65.9% 64 / 97 Podpod 7.8% 3 / 38 totaltotal 66.3% 343 / 517 CC 34 SCAR 18.0
CC
34
Cov
76%
xpath_cmp
30.0
_xpath_elt_cmp
21.3
new
20.3
CRAP 6.1
↑ Summary
1 package PPIx::XPath;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Scalar::Util qw(reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Tree::XPathEngine;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 our $VERSION = '2.02'; # VERSION
10  
11 # ABSTRACT: an XPath implementation for the PDOM
12  
13  
14 1 ▶sub new {
Subroutine new: called CC=8 SCAR=30.1
Pod documented
15 1 my ($class,$source) = @_;
16  
17 1 ▶ croak "PPIx::XPath->new needs a source document" unless defined($source);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source 0 1 1
18  
19 1 my $doc;
20 1 ▶ if (blessed($source) && $source->isa('PPI::Node')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($source) and $source->isa('PPI::Node')) { } 0 1 1
elsif (builtin::reftype($source) eq 'SCALAR' or not ref $source and -f $source) { } 1 0 1
Condition33%1/3
builtin::blessed($source) and $source->isa("PPI::Node")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($source) and $source->isa("PPI::Node")
builtin::blessed($source) $source->isa("PPI::Node")
Truth table33%1/3
A and B
A= builtin::blessed($source)B= $source->isa("PPI::Node")
ABresult
0X0
100
111
21 0 $doc = $source;
22 }
23 ▶ elsif (reftype($source) eq 'SCALAR'
Condition16%1/6
builtin::reftype($source) eq "SCALAR" or not ref $source and -f $source
l!l&&r!l&&!r
100
not ref $source and -f $source
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::reftype($source) eq "SCALAR" or not ref $source and -f $source
builtin::reftype($source) eq "SCALAR" not ref $source -f $source
Truth table25%1/4
A or not(B) and C
A= builtin::reftype($source) eq "SCALAR"B= not ref $sourceC= -f $source
ABCresult
1XX1
0111
00X0
0100
24 or (!ref($source) && -f $source)) {
25 1 $doc = PPI::Document->new($source);
26 }
27 else {
28 0 ▶ croak "PPIx::XPath expects either a PPI::Node or a file" .
Condition0%0/3
ref $source || $source
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $source || $source
ref $source $source
Truth table0%0/3
A || B
A= ref $sourceB= $source
ABresult
1X1
011
000
29 " got a: [" .( ref($source) || $source ). ']';
30 }
31  
32 1 return bless {doc=>$doc},$class;
33 }
34  
35  
36 {
37 3 my $legacy_names_rx;my %new_name_for;
38 3 ▶ sub clean_xpath_expr {
Subroutine clean_xpath_expr: called CC=1 SCAR=0.0
Pod documented
39 3 my (undef,$expr)=@_;
40  
41 3 $expr =~ s{$legacy_names_rx}{$new_name_for{$1}}ge;
42  
43 3 return $expr;
44 }
45  
46 3 my @PPI_Packs;
47 # taken from Devel::Symdump
48 # breadth-first search of packages under C<PPI>
49 3 my @packages=('PPI');
50 3 ▶ while (my $pack=shift(@packages)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pack = shift @packages) 270 3 273
51 270 my %pack_symbols = do {
52 3 ▶ no strict 'refs'; ## no critic(ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
53 270 %{*{"$pack\::"}}
54 };
55 270 ▶ while (my ($key,$val)=each(%pack_symbols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %pack_symbols) 2751 270 3021
56 # that {HASH} lookup is special for typeglobs, so we have
57 # to alias a local typeglob to make it work
58 2751 local *ENTRY=$val;
59 # does this symbol table entry look like a sub-package?
60 2751 ▶ if (defined $val && defined *ENTRY{HASH} && $key=~/::$/
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/ and not $key =~ /^::/ and $key ne "main::" and $key ne "<none>::") 267 2484 2751
Condition73%11/15
defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/ and not $key =~ /^::/ and $key ne "main::" and $key ne "<none>::"
!ll&&!rl&&r
24840267
defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/ and not $key =~ /^::/ and $key ne "main::"
!ll&&!rl&&r
24840267
defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/ and not $key =~ /^::/
!ll&&!rl&&r
24840267
defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/
!ll&&!rl&&r
241866267
defined $val and defined *ENTRY{"HASH"}
!ll&&!rl&&r
02418333
MC/DC33%2/6
defined $val and defined *ENTRY{"HASH"} and $key =~ /::$/ and not $key =~ /^::/ and $key ne "main::" and $key ne "<none>::"
defined $val defined *ENTRY{"HASH"} $key =~ /::$/ not $key =~ /^::/ $key ne "main::" $key ne "<none>::"
Truth table42%3/7
A and B and C and not(D) and E and F
A= defined $valB= defined *ENTRY{"HASH"}C= $key =~ /::$/D= not $key =~ /^::/E= $key ne "main::"F= $key ne "<none>::"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
61 && $key !~ /^::/
62 && $key ne 'main::' && $key ne '<none>::') {
63  
64 # add it to the search list
65 267 my $p = "$pack\::$key";$p =~ s{::$}{};
66 267 push @packages,$p;
67  
68 # and add it to the map of names
69 267 $p =~ s{^PPI::}{};
70 267 ▶ next unless $p=~/::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ /::/ 39 228 267
71  
72 228 my $newname=$p;
73 228 $newname =~ s{::}{-}g;
74 228 push @PPI_Packs,$p;
75 228 $new_name_for{$p}=$newname;
76 }
77 }
78 }
79  
80 # @PPI_Packs now contains all the old-style names, build a regex
81 # to match them (the sort is important, we want to match longer
82 # names first!)
83 $legacy_names_rx='\b('.join(q{|},
84 3 sort {length($b) <=> length($a)} @PPI_Packs
85 ).')\b';
86 3 $legacy_names_rx=qr{$legacy_names_rx};
87 }
88  
89  
90 3 ▶sub match {
Subroutine match: called CC=1 SCAR=0.0
Pod documented
91 3 my ($self,$expr) = @_;
92  
93 3 $expr=$self->clean_xpath_expr($expr);
94  
95 3 Tree::XPathEngine->new()->findnodes($expr,$self->{doc});
96 }
97  
98  
99 package PPI::Element; ## no critic(ProhibitMultiplePackages)
100 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 67 ▶sub xpath_get_name { my $pack_name=substr($_[0]->class,5);
Subroutine xpath_get_name: called CC=1 SCAR=0.0
Pod undocumented
104 67 $pack_name =~ s/::/-/g;
105 67 $pack_name }
106 0 ▶sub xpath_get_next_sibling { $_[0]->snext_sibling }
Subroutine xpath_get_next_sibling: not called CC=1 SCAR=6.9
Pod undocumented
107 0 ▶sub xpath_get_previous_sibling { $_[0]->sprevious_sibling }
Subroutine xpath_get_previous_sibling: not called CC=1 SCAR=6.9
Pod undocumented
108 0 ▶sub xpath_get_root_node { $_[0]->top }
Subroutine xpath_get_root_node: not called CC=1 SCAR=6.9
Pod undocumented
109 0 ▶sub xpath_get_parent_node { $_[0]->parent }
Subroutine xpath_get_parent_node: not called CC=1 SCAR=6.9
Pod undocumented
110 67 ▶sub xpath_is_element_node { 1 }
Subroutine xpath_is_element_node: called CC=1 SCAR=0.0
Pod undocumented
111 0 ▶sub xpath_is_attribute_node { 0 }
Subroutine xpath_is_attribute_node: not called CC=1 SCAR=6.9
Pod undocumented
112 0 ▶sub xpath_is_document_node { 0 }
Subroutine xpath_is_document_node: not called CC=1 SCAR=6.9
Pod undocumented
113 4 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: called CC=1 SCAR=0.0
Pod undocumented
114 return
115 4 PPIx::XPath::Attr->new($_[0],'significant'),
116 PPIx::XPath::Attr->new($_[0],'content'),
117 }
118 0 ▶sub xpath_to_literal { "$_[0]" }
Subroutine xpath_to_literal: not called CC=1 SCAR=6.9
Pod undocumented
119 0 ▶sub xpath_get_value { "$_[0]" }
Subroutine xpath_get_value: not called CC=1 SCAR=6.9
Pod undocumented
120 1 ▶sub xpath_string_value { "$_[0]" }
Subroutine xpath_string_value: called CC=1 SCAR=0.0
Pod undocumented
121  
122 63 ▶sub xpath_cmp {
Subroutine xpath_cmp: called CC=4 SCAR=18.9
Pod undocumented
123 63 my( $a, $b)= @_;
124 63 ▶ if ( UNIVERSAL::isa( $b, 'PPIx::XPath::Attr')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($b, 'PPIx::XPath::Attr')) { } 0 63 63
elsif (UNIVERSAL::isa($b, 'PPI::Document')) { } 0 63 63
125 # elt <=> att, compare the elt to the att->{elt}
126 # if the elt is the att->{elt} (cmp return 0) then -1, elt is before att
127 0 ▶ return ($a->_xpath_elt_cmp( $b->{parent}) ) || -1 ;
Condition0%0/2
$a->_xpath_elt_cmp($b->{'parent'}) || -1
l!l
00
MC/DC0%0/1
$a->_xpath_elt_cmp($b->{'parent'}) || -1
$a->_xpath_elt_cmp($b->{'parent'})
Truth table0%0/2
A
A= $a->_xpath_elt_cmp($b->{'parent'})
Aresult
11
00
128 }
129 elsif ( UNIVERSAL::isa( $b, 'PPI::Document')) {
130 # elt <=> document, elt is after document
131 0 return 1;
132 } else {
133 # 2 elts, compare them
134 63 return $a->_xpath_elt_cmp( $b);
135 }
136 }
137  
138 63 ▶sub _xpath_elt_cmp {
Subroutine _xpath_elt_cmp: called CC=14 SCAR=30.6
139 63 my ($a,$b)=@_;
140  
141 # easy cases
142 63 ▶ return 0 if( $a == $b);
Branch: 1 branch
BranchTrueFalseTotal
if $a == $b 0 63 63
143 63 ▶ return 1 if( $a->_xpath_in($b)); # a starts after b
Branch: 1 branch
BranchTrueFalseTotal
if $a->_xpath_in($b) 15 48 63
144 48 ▶ return -1 if( $b->_xpath_in($a)); # a starts before b
Branch: 1 branch
BranchTrueFalseTotal
if $b->_xpath_in($a) 6 42 48
145  
146 # ancestors does not include the element itself
147 42 my @a_pile= ($a, $a->_xpath_ancestors);
148 42 my @b_pile= ($b, $b->_xpath_ancestors);
149  
150 # the 2 elements are not in the same twig
151 42 ▶ return undef unless( $a_pile[-1] == $b_pile[-1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $a_pile[-1] == $b_pile[-1] 0 42 42
152  
153 # find the first non common ancestors (they are siblings)
154 42 my $a_anc= pop @a_pile;
155 42 my $b_anc= pop @b_pile;
156  
157 42 ▶ while( $a_anc == $b_anc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_anc == $b_anc) 83 42 125
158 83 $a_anc= pop @a_pile;
159 83 $b_anc= pop @b_pile;
160 }
161  
162 # from there move left and right and figure out the order
163 42 my( $a_prev, $a_next, $b_prev, $b_next)= ($a_anc, $a_anc, $b_anc, $b_anc);
164 42 while () {
165 42 ▶ $a_prev= $a_prev->sprevious_sibling || return( -1);
Condition100%2/2
$a_prev->sprevious_sibling || (return -1)
l!l
1923
MC/DC100%1/1
$a_prev->sprevious_sibling || (return -1)
$a_prev->sprevious_sibling
Truth table100%2/2
A
A= $a_prev->sprevious_sibling
Aresult
11
00
166 19 ▶ return 1 if( $a_prev == $b_next);
Branch: 1 branch
BranchTrueFalseTotal
if $a_prev == $b_next 16 3 19
167 3 ▶ $a_next= $a_next->snext_sibling || return( 1);
Condition50%1/2
$a_next->snext_sibling || (return 1)
l!l
30
MC/DC0%0/1
$a_next->snext_sibling || (return 1)
$a_next->snext_sibling
Truth table50%1/2
A
A= $a_next->snext_sibling
Aresult
11
00
168 3 ▶ return -1 if( $a_next == $b_prev);
Branch: 1 branch
BranchTrueFalseTotal
if $a_next == $b_prev 3 0 3
169 0 ▶ $b_prev= $b_prev->sprevious_sibling || return( 1);
Condition0%0/2
$b_prev->sprevious_sibling || (return 1)
l!l
00
MC/DC0%0/1
$b_prev->sprevious_sibling || (return 1)
$b_prev->sprevious_sibling
Truth table0%0/2
A
A= $b_prev->sprevious_sibling
Aresult
11
00
170 0 ▶ return -1 if( $b_prev == $a_next);
Branch: 1 branch
BranchTrueFalseTotal
if $b_prev == $a_next 0 0 0
171 0 ▶ $b_next= $b_next->snext_sibling || return( -1);
Condition0%0/2
$b_next->snext_sibling || (return -1)
l!l
00
MC/DC0%0/1
$b_next->snext_sibling || (return -1)
$b_next->snext_sibling
Truth table0%0/2
A
A= $b_next->snext_sibling
Aresult
11
00
172 0 ▶ return 1 if( $b_next == $a_prev);
Branch: 1 branch
BranchTrueFalseTotal
if $b_next == $a_prev 0 0 0
173 }
174 }
175  
176 111 ▶sub _xpath_in {
Subroutine _xpath_in: called CC=3 SCAR=11.0
177 111 my ($self, $ancestor)= @_;
178 111 ▶ while ( $self= $self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self = $self->parent) 250 90 340
179 250 ▶ return $self if ( $self == $ancestor);
Branch: 1 branch
BranchTrueFalseTotal
if $self == $ancestor 21 229 250
180 }
181 }
182  
183 84 ▶sub _xpath_ancestors {
Subroutine _xpath_ancestors: called CC=2 SCAR=6.9
184 84 my( $self)= @_;
185 84 my @ancestors;
186 84 ▶ while ( $self= $self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self = $self->parent) 213 84 297
187 213 push @ancestors, $self;
188 }
189 84 return @ancestors;
190 }
191  
192 package PPI::Token; ## no critic(ProhibitMultiplePackages)
193 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 28 ▶sub xpath_get_child_nodes { return }
Subroutine xpath_get_child_nodes: called CC=1 SCAR=0.0
Pod undocumented
197  
198 package PPI::Token::Quote::Double; ## no critic(ProhibitMultiplePackages)
199 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
200 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
201  
202 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
203 0 return $_[0]->SUPER::xpath_get_attributes,
204 PPIx::XPath::Attr->new($_[0],'interpolations'),
205 }
206  
207 package PPI::Token::Number; ## no critic(ProhibitMultiplePackages)
208 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
212 0 return $_[0]->SUPER::xpath_get_attributes,
213 PPIx::XPath::Attr->new($_[0],'base'),
214 }
215  
216 package PPI::Token::Word; ## no critic(ProhibitMultiplePackages)
217 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
218 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
219  
220 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
221 0 return $_[0]->SUPER::xpath_get_attributes,
222 PPIx::XPath::Attr->new($_[0],'method-call'),
223 }
224  
225 package PPI::Token::Comment; ## no critic(ProhibitMultiplePackages)
226 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
227 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
228  
229 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
230 0 return $_[0]->SUPER::xpath_get_attributes,
231 PPIx::XPath::Attr->new($_[0],'line'),
232 }
233  
234 package PPI::Token::HereDoc; ## no critic(ProhibitMultiplePackages)
235 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
236 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
237  
238 # TODO: add access to the contents of the heredoc (->heredoc method)
239  
240 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
241 0 return $_[0]->SUPER::xpath_get_attributes,
242 PPIx::XPath::Attr->new($_[0],'terminator'),
243 }
244  
245 package PPI::Token::Prototype; ## no critic(ProhibitMultiplePackages)
246 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
247 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
248  
249 0 ▶sub xpath_to_literal { $_[0]->prototype }
Subroutine xpath_to_literal: not called CC=1 SCAR=6.9
Pod undocumented
250 0 ▶sub xpath_get_value { $_[0]->prototype }
Subroutine xpath_get_value: not called CC=1 SCAR=6.9
Pod undocumented
251 0 ▶sub xpath_string_value { $_[0]->prototype }
Subroutine xpath_string_value: not called CC=1 SCAR=6.9
Pod undocumented
252  
253 package PPI::Node; ## no critic(ProhibitMultiplePackages)
254 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
255 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
256  
257 42 ▶sub xpath_get_child_nodes { $_[0]->schildren }
Subroutine xpath_get_child_nodes: called CC=1 SCAR=0.0
Pod undocumented
258 4 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: called CC=1 SCAR=0.0
Pod undocumented
259 4 return $_[0]->SUPER::xpath_get_attributes,
260 PPIx::XPath::Attr->new($_[0],'scope'),
261 }
262  
263 package PPI::Token::Attribute; ## no critic(ProhibitMultiplePackages)
264 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
265 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
266  
267 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
268 0 return $_[0]->SUPER::xpath_get_attributes,
269 PPIx::XPath::Attr->new($_[0],'identifier'),
270 PPIx::XPath::Attr->new($_[0],'parameters'),
271 }
272  
273 package PPI::Token::Symbol; ## no critic(ProhibitMultiplePackages)
274 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
275 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
276  
277 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
278 0 return $_[0]->SUPER::xpath_get_attributes,
279 PPIx::XPath::Attr->new($_[0],'symbol'),
280 PPIx::XPath::Attr->new($_[0],'canonical'),
281 PPIx::XPath::Attr->new($_[0],'raw_type'),
282 PPIx::XPath::Attr->new($_[0],'symbol_typel'),
283 }
284  
285 package PPI::Statement; ## no critic(ProhibitMultiplePackages)
286 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
287 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
288  
289 4 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: called CC=1 SCAR=0.0
Pod undocumented
290 4 return $_[0]->SUPER::xpath_get_attributes,
291 PPIx::XPath::Attr->new($_[0],'label'),
292 PPIx::XPath::Attr->new($_[0],'stable'),
293 PPIx::XPath::Attr->new($_[0],'type'),
294 }
295  
296 package PPI::Statement::Sub; ## no critic(ProhibitMultiplePackages)
297 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
298 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
299  
300 4 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: called CC=1 SCAR=0.0
Pod undocumented
301 4 return $_[0]->SUPER::xpath_get_attributes,
302 PPIx::XPath::Attr->new($_[0],'name'),
303 PPIx::XPath::Attr->new($_[0],'prototype'),
304 PPIx::XPath::Attr->new($_[0],'forward'),
305 PPIx::XPath::Attr->new($_[0],'reserved'),
306 }
307  
308 package PPI::Statement::Package; ## no critic(ProhibitMultiplePackages)
309 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
310 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
311  
312 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
313 0 return $_[0]->SUPER::xpath_get_attributes,
314 PPIx::XPath::Attr->new($_[0],'namespace'),
315 PPIx::XPath::Attr->new($_[0],'file-scoped'),
316 }
317  
318 package PPI::Statement::Include; ## no critic(ProhibitMultiplePackages)
319 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
320 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
321  
322 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
323 0 return $_[0]->SUPER::xpath_get_attributes,
324 PPIx::XPath::Attr->new($_[0],'module'),
325 PPIx::XPath::Attr->new($_[0],'module-version'),
326 PPIx::XPath::Attr->new($_[0],'version'),
327 PPIx::XPath::Attr->new($_[0],'version-literal'),
328 PPIx::XPath::Attr->new($_[0],'pragma'),
329 }
330  
331 package PPI::Structure; ## no critic(ProhibitMultiplePackages)
332 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
333 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
334  
335 0 ▶sub xpath_get_attributes {
Subroutine xpath_get_attributes: not called CC=1 SCAR=6.9
Pod undocumented
336 0 return $_[0]->SUPER::xpath_get_attributes,
337 PPIx::XPath::Attr->new($_[0],'start'),
338 PPIx::XPath::Attr->new($_[0],'finish'),
339 PPIx::XPath::Attr->new($_[0],'braces'),
340 }
341  
342 package PPI::Document; ## no critic(ProhibitMultiplePackages)
343 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
344 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
345  
346 7 ▶sub xpath_get_root_node { $_[0] }
Subroutine xpath_get_root_node: called CC=1 SCAR=0.0
Pod undocumented
347 0 ▶sub xpath_get_parent_node { return }
Subroutine xpath_get_parent_node: not called CC=1 SCAR=6.9
Pod undocumented
348 0 ▶sub xpath_is_attribute_node { 0 }
Subroutine xpath_is_attribute_node: not called CC=1 SCAR=6.9
Pod undocumented
349 0 ▶sub xpath_is_document_node { 1 }
Subroutine xpath_is_document_node: not called CC=1 SCAR=6.9
Pod undocumented
350  
351 package PPIx::XPath::Attr; ## no critic(ProhibitMultiplePackages)
352 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
353 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
354  
355 40 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
356 40 my ($class,$parent,$name)=@_;
357  
358 40 my $meth=$parent->can($name);
359 40 ▶ return unless $meth;
Branch: 1 branch
BranchTrueFalseTotal
unless $meth 0 40 40
360  
361 40 my $value;
362 40 ▶ eval {$value=$meth->($parent);1} or return;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $value = &$meth($parent); 1 } } or return 36 4 40
363  
364 36 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 8 28 36
365  
366 28 return bless {parent=>$parent,name=>$name,value=>$value},$class;
367 }
368  
369 28 ▶sub xpath_get_name { $_[0]->{name} }
Subroutine xpath_get_name: called CC=1 SCAR=0.0
370 0 ▶sub xpath_get_root_node { $_[0]->{parent}->top }
Subroutine xpath_get_root_node: not called CC=1 SCAR=6.9
371 0 ▶sub xpath_get_parent_node { $_[0]->{parent} }
Subroutine xpath_get_parent_node: not called CC=1 SCAR=6.9
372 0 ▶sub xpath_is_element_node { 0 }
Subroutine xpath_is_element_node: not called CC=1 SCAR=6.9
373 0 ▶sub xpath_is_attribute_node { 1 }
Subroutine xpath_is_attribute_node: not called CC=1 SCAR=6.9
374 0 ▶sub xpath_is_document_node { 0 }
Subroutine xpath_is_document_node: not called CC=1 SCAR=6.9
375 0 ▶sub xpath_to_literal { $_[0]->{value} }
Subroutine xpath_to_literal: not called CC=1 SCAR=6.9
376 0 ▶sub xpath_get_value { $_[0]->{value} }
Subroutine xpath_get_value: not called CC=1 SCAR=6.9
377 4 ▶sub xpath_string_value { $_[0]->{value} }
Subroutine xpath_string_value: called CC=1 SCAR=0.0
378 0 ▶sub xpath_to_number { Tree::XPathEngine::Number->new($_[0]->{value}) }
Subroutine xpath_to_number: not called CC=1 SCAR=6.9
379  
380 0 ▶sub xpath_cmp {
Subroutine xpath_cmp: not called CC=5 SCAR=34.0
381 0 my( $a, $b)= @_;
382 0 ▶ if ( UNIVERSAL::isa( $b, 'PPIx::XPath::Attr')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($b, 'PPIx::XPath::Attr')) { } 0 0 0
elsif (UNIVERSAL::isa($b, 'PPI::Document')) { } 0 0 0
383 # 2 attributes, compare their elements, then their name
384 return ($a->{parent}->_xpath_elt_cmp( $b->{parent}) )
385 0 ▶ || ($a->{name} cmp $b->{name});
Condition0%0/3
$a->{'parent'}->_xpath_elt_cmp($b->{'parent'}) || $a->{'name'} cmp $b->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$a->{'parent'}->_xpath_elt_cmp($b->{'parent'}) || $a->{'name'} cmp $b->{'name'}
$a->{'parent'}->_xpath_elt_cmp($b->{'parent'}) $a->{'name'} cmp $b->{'name'}
Truth table0%0/3
A || B
A= $a->{'parent'}->_xpath_elt_cmp($b->{'parent'})B= $a->{'name'} cmp $b->{'name'}
ABresult
1X1
011
000
386 }
387 elsif ( UNIVERSAL::isa( $b, 'PPI::Document')) {
388 # att <=> document, att is after document
389 0 return 1;
390 }
391 else {
392 # att <=> elt : compare the att->elt and the elt
393 # if att->elt is the elt (cmp returns 0) then 1 (elt is before att)
394 0 ▶ return ($a->{parent}->_xpath_elt_cmp( $b) ) || 1 ;
Condition0%0/2
$a->{'parent'}->_xpath_elt_cmp($b) || 1
l!l
00
MC/DC0%0/1
$a->{'parent'}->_xpath_elt_cmp($b) || 1
$a->{'parent'}->_xpath_elt_cmp($b)
Truth table0%0/2
A
A= $a->{'parent'}->_xpath_elt_cmp($b)
Aresult
11
00
395 }
396 }
397  
398 3 1;
399  
400 __END__
↑ Summary