File Coverage

blib/lib/WWW/Mechanize/Plugin/Selector.pm
Criterion Covered Total %
statement 6 14 42.8
branch 0 4 0.0
condition 0 5 0.0
subroutine 2 3 66.6
pod 1 1 100.0
total 9 27 33.3


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