lib/HTML/Element/AbsoluteXPath.pm

filter: Statementstmt 100% 44 / 44 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 96.7% 59 / 61 SCAR 23.0
CC
10
Cov
98%
abs_xpath
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 10.0
« blib/lib/HTML/Element/AbsoluteXPath.pm ↑ Summary
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package HTML::Element::AbsoluteXPath;
4  
5 # ABSTRACT: Add absolute XPath support to HTML::Element
6  
7 3 our $VERSION = '0.02'; # VERSION
8  
9 3 ▶use HTML::Element 5.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub HTML::Element::abs_xpath{
12 14 ▶ my $self = shift;
Subroutine abs_xpath: called CC=10 SCAR=23.0
Pod undocumented
13 14 my @hint = @_;
14
15 14 ▶ push(@hint,'_tag') unless grep{$_ eq '_tag'}@hint;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "_tag";} @hint 14 0 14
16  
17 14 my $raddr = $self->root()->address;
18 14 my @lin;
19 14 my $ee = $self;
20 14 ▶ while( $ee->address ne $raddr ){
Branch: 1 branch
BranchTrueFalseTotal
if ($ee->address ne $raddr) 28 14 42
21 28 my $p = $ee->parent();
22 28 my %filters;
23 28 foreach (sort @hint){
24 64 my $v = $ee->attr($_);
25 64 ▶ next unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 26 38 64
26 38 $filters{$_} = $v;
27 }
28 28 my @sib = $p->look_down(%filters);
29  
30 28 @sib = grep{$_->depth() == $ee->depth()}@sib;
31 28 my $idx = 1;
32 28 foreach (@sib){
33 40 ▶ last if $_->address eq $ee->address;
Branch: 1 branch
BranchTrueFalseTotal
if $_->address eq $ee->address 28 12 40
34 12 $idx++;
35 }
36  
37 28 my @attrs;
38 28 foreach (keys %filters){
39 38 ▶ next if $_ eq '_tag';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "_tag" 28 10 38
40 10 my $v = $filters{$_};
41 10 my $pat = "\@$_='$v'";
42 10 push(@attrs,$pat);
43 }
44  
45 28 my $attr = '';
46 28 ▶ $attr = "[".join(' and ',@attrs)."]" if @attrs;
Branch: 1 branch
BranchTrueFalseTotal
if @attrs 9 19 28
47  
48 28 push(@lin, $ee->tag() . $attr . "[$idx]" );
49 28 $ee = $p;
50 }
51 14 push(@lin, $ee->tag().'[1]' );
52 14 return '/'.join('/',reverse @lin);
53 }
54  
55  
56  
57  
58 3 1;
59  
60 __END__
« blib/lib/HTML/Element/AbsoluteXPath.pm ↑ Summary