line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
28289
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
76
|
|
2
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
171
|
|
3
|
|
|
|
|
|
|
package HTML::Element::AbsoluteXPath; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Add absolute XPath support to HTML::Element |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.0'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
15
|
use HTML::Element 5.03; |
|
3
|
|
|
|
|
83
|
|
|
3
|
|
|
|
|
22
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub HTML::Element::abs_xpath{ |
12
|
14
|
|
|
14
|
0
|
5261
|
my $self = shift; |
13
|
14
|
|
|
|
|
30
|
my @hint = @_; |
14
|
|
|
|
|
|
|
|
15
|
14
|
50
|
|
|
|
28
|
push(@hint,'_tag') unless grep{$_ eq '_tag'}@hint; |
|
16
|
|
|
|
|
59
|
|
16
|
|
|
|
|
|
|
|
17
|
14
|
|
|
|
|
44
|
my $raddr = $self->root()->address; |
18
|
14
|
|
|
|
|
328
|
my @lin; |
19
|
14
|
|
|
|
|
18
|
my $ee = $self; |
20
|
14
|
|
|
|
|
40
|
while( $ee->address ne $raddr ){ |
21
|
28
|
|
|
|
|
1060
|
my $p = $ee->parent(); |
22
|
28
|
|
|
|
|
145
|
my %filters; |
23
|
28
|
|
|
|
|
80
|
foreach (sort @hint){ |
24
|
64
|
|
|
|
|
168
|
my $v = $ee->attr($_); |
25
|
64
|
100
|
|
|
|
625
|
next unless $v; |
26
|
38
|
|
|
|
|
95
|
$filters{$_} = $v; |
27
|
|
|
|
|
|
|
} |
28
|
28
|
|
|
|
|
101
|
my @sib = $p->look_down(%filters); |
29
|
|
|
|
|
|
|
|
30
|
28
|
|
|
|
|
2993
|
@sib = grep{$_->depth() == $ee->depth()}@sib; |
|
53
|
|
|
|
|
513
|
|
31
|
28
|
|
|
|
|
943
|
my $idx = 1; |
32
|
28
|
|
|
|
|
50
|
foreach (@sib){ |
33
|
40
|
100
|
|
|
|
95
|
last if $_->address eq $ee->address; |
34
|
12
|
|
|
|
|
970
|
$idx++; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
28
|
|
|
|
|
1936
|
my @attrs; |
38
|
28
|
|
|
|
|
76
|
foreach (sort keys %filters){ |
39
|
38
|
100
|
|
|
|
92
|
next if $_ eq '_tag'; |
40
|
10
|
|
|
|
|
19
|
my $v = $filters{$_}; |
41
|
10
|
|
|
|
|
24
|
my $pat = "\@$_='$v'"; |
42
|
10
|
|
|
|
|
21
|
push(@attrs,$pat); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
28
|
|
|
|
|
46
|
my $attr = ''; |
46
|
28
|
100
|
|
|
|
71
|
$attr = "[".join(' and ',@attrs)."]" if @attrs; |
47
|
|
|
|
|
|
|
|
48
|
28
|
|
|
|
|
78
|
push(@lin, $ee->tag() . $attr . "[$idx]" ); |
49
|
28
|
|
|
|
|
262
|
$ee = $p; |
50
|
|
|
|
|
|
|
} |
51
|
14
|
|
|
|
|
217
|
push(@lin, $ee->tag().'[1]' ); |
52
|
14
|
|
|
|
|
150
|
return '/'.join('/',reverse @lin); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |