line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
38956
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
142
|
|
2
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
216
|
|
3
|
|
|
|
|
|
|
package HTML::Element::AbsoluteXPath; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Add absolute XPath support to HTML::Element |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
30
|
use HTML::Element 5.03; |
|
3
|
|
|
|
|
98
|
|
|
3
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub HTML::Element::abs_xpath{ |
12
|
14
|
|
|
14
|
0
|
6438
|
my $self = shift; |
13
|
14
|
|
|
|
|
32
|
my @hint = @_; |
14
|
|
|
|
|
|
|
|
15
|
14
|
50
|
|
|
|
30
|
push(@hint,'_tag') unless grep{$_ eq '_tag'}@hint; |
|
16
|
|
|
|
|
56
|
|
16
|
|
|
|
|
|
|
|
17
|
14
|
|
|
|
|
58
|
my $raddr = $self->root()->address; |
18
|
14
|
|
|
|
|
342
|
my @lin; |
19
|
14
|
|
|
|
|
17
|
my $ee = $self; |
20
|
14
|
|
|
|
|
37
|
while( $ee->address ne $raddr ){ |
21
|
28
|
|
|
|
|
1044
|
my $p = $ee->parent(); |
22
|
28
|
|
|
|
|
140
|
my %filters; |
23
|
28
|
|
|
|
|
88
|
foreach (sort @hint){ |
24
|
64
|
|
|
|
|
167
|
my $v = $ee->attr($_); |
25
|
64
|
100
|
|
|
|
629
|
next unless $v; |
26
|
38
|
|
|
|
|
108
|
$filters{$_} = $v; |
27
|
|
|
|
|
|
|
} |
28
|
28
|
|
|
|
|
175
|
my @sib = $p->look_down(%filters); |
29
|
|
|
|
|
|
|
|
30
|
28
|
|
|
|
|
2910
|
@sib = grep{$_->depth() == $ee->depth()}@sib; |
|
53
|
|
|
|
|
486
|
|
31
|
28
|
|
|
|
|
431
|
my $idx = 1; |
32
|
28
|
|
|
|
|
44
|
foreach (@sib){ |
33
|
40
|
100
|
|
|
|
103
|
last if $_->address eq $ee->address; |
34
|
12
|
|
|
|
|
1016
|
$idx++; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
28
|
|
|
|
|
1861
|
my @attrs; |
38
|
28
|
|
|
|
|
60
|
foreach (keys %filters){ |
39
|
38
|
100
|
|
|
|
97
|
next if $_ eq '_tag'; |
40
|
10
|
|
|
|
|
17
|
my $v = $filters{$_}; |
41
|
10
|
|
|
|
|
23
|
my $pat = "\@$_='$v'"; |
42
|
10
|
|
|
|
|
25
|
push(@attrs,$pat); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
28
|
|
|
|
|
44
|
my $attr = ''; |
46
|
28
|
100
|
|
|
|
73
|
$attr = "[".join(' and ',@attrs)."]" if @attrs; |
47
|
|
|
|
|
|
|
|
48
|
28
|
|
|
|
|
79
|
push(@lin, $ee->tag() . $attr . "[$idx]" ); |
49
|
28
|
|
|
|
|
273
|
$ee = $p; |
50
|
|
|
|
|
|
|
} |
51
|
14
|
|
|
|
|
222
|
push(@lin, $ee->tag().'[1]' ); |
52
|
14
|
|
|
|
|
177
|
return '/'.join('/',reverse @lin); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |