line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Mechanize::Plugin::Selector; |
2
|
32
|
|
|
32
|
|
247
|
use strict; |
|
32
|
|
|
|
|
78
|
|
|
32
|
|
|
|
|
1099
|
|
3
|
32
|
|
|
32
|
|
192
|
use vars qw($VERSION); |
|
32
|
|
|
|
|
71
|
|
|
32
|
|
|
|
|
1857
|
|
4
|
|
|
|
|
|
|
$VERSION= '0.22'; |
5
|
32
|
|
|
32
|
|
15443
|
use HTML::Selector::XPath 'selector_to_xpath'; |
|
32
|
|
|
|
|
88726
|
|
|
32
|
|
|
|
|
5675
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
WWW::Mechanize::Plugin::Selector - CSS selector method for WWW::Mechanize |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ADDED METHODS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 C<< $mech->selector( $css_selector, %options ) >> |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my @text = $mech->selector('p.content'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Returns all nodes matching the given CSS selector. If |
22
|
|
|
|
|
|
|
C<$css_selector> is an array reference, it returns |
23
|
|
|
|
|
|
|
all nodes matched by any of the CSS selectors in the array. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This takes the same options that C<< ->xpath >> does. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub selector { |
30
|
0
|
|
|
0
|
1
|
|
my ($self,$query,%options) = @_; |
31
|
0
|
|
0
|
|
|
|
$options{ user_info } ||= "CSS selector '$query'"; |
32
|
0
|
0
|
0
|
|
|
|
if ('ARRAY' ne (ref $query || '')) { |
33
|
0
|
|
|
|
|
|
$query = [$query]; |
34
|
|
|
|
|
|
|
}; |
35
|
0
|
0
|
|
|
|
|
my $root = $options{ node } ? './' : ''; |
36
|
0
|
|
|
|
|
|
my @q = map { selector_to_xpath($_, root => $root) } @$query; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->xpath(\@q, %options); |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |