line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
148124
|
use 5.008; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
17857
|
|
2
|
2
|
|
|
2
|
|
24
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
3
|
2
|
|
|
2
|
|
3675
|
use utf8; |
|
2
|
|
|
|
|
31
|
|
|
2
|
|
|
|
|
221
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package XML::LibXML::QuerySelector; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
28976
|
use HTML::Selector::XPath 0.13 qw//; |
|
2
|
|
|
|
|
25214
|
|
|
2
|
|
|
|
|
97
|
|
8
|
2
|
|
|
2
|
|
2877
|
use XML::LibXML 1.70 qw//; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN |
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
13
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
push @XML::LibXML::Document::ISA, __PACKAGE__; |
16
|
|
|
|
|
|
|
push @XML::LibXML::DocumentFragment::ISA, __PACKAGE__; |
17
|
|
|
|
|
|
|
push @XML::LibXML::Element::ISA, __PACKAGE__; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $contains = sub |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
my ($node) = @_; |
24
|
|
|
|
|
|
|
my $self_path = $self->nodePath; |
25
|
|
|
|
|
|
|
my $node_path = $node->nodePath; |
26
|
|
|
|
|
|
|
my $sub_node_path = substr $node_path, 0, length $self_path; |
27
|
|
|
|
|
|
|
$sub_node_path eq $self_path; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub querySelectorAll |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
my ($selector_string) = @_; |
34
|
|
|
|
|
|
|
my $selector = "HTML::Selector::XPath"->new($selector_string); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $document = $self->nodeName =~ /^#/ ? $self : $self->ownerDocument; |
37
|
|
|
|
|
|
|
my $nsuri = $document->documentElement->lookupNamespaceURI(''); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $xc = "XML::LibXML::XPathContext"->new($document); |
40
|
|
|
|
|
|
|
$xc->registerNs(defaultns => $nsuri) if $nsuri; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $xpath = defined $nsuri |
43
|
|
|
|
|
|
|
? $selector->to_xpath(prefix => 'defaultns') |
44
|
|
|
|
|
|
|
: $selector->to_xpath; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if ($document == $self) |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
return $xc->findnodes($xpath); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my @results = map |
52
|
|
|
|
|
|
|
{ $self->$contains($_) ? ($_) : () } |
53
|
|
|
|
|
|
|
@{[ $xc->findnodes($xpath) ]}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
wantarray ? @results : "XML::LibXML::NodeList"->new(@results); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub querySelector |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my ($selector_string) = @_; |
62
|
|
|
|
|
|
|
my $results = $self->querySelectorAll($selector_string); |
63
|
|
|
|
|
|
|
return unless $results->size; |
64
|
|
|
|
|
|
|
$results->shift; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__FILE__ |
68
|
|
|
|
|
|
|
__END__ |