blib/lib/WWW/Mechanize/Plugin/Selector.pm

filter: Statementstmt 57.8% 11 / 19 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 44.1% 15 / 34 CC 5 SCAR 29.5
CC
5
Cov
41%
selector
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 19.1
↑ Summary
1 package WWW::Mechanize::Plugin::Selector;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $VERSION= '0.16';
5 1 ▶use HTML::Selector::XPath 'selector_to_xpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 SYNOPSIS
8  
9 =head1 NAME
10  
11 WWW::Mechanize::Plugin::Selector - CSS selector method for WWW::Mechanize
12  
13 =head1 DESCRIPTION
14  
15 This is a plugin (or "Role", for some) which supplies the C<< ->selector >>
16 method to your WWW::Mechanize object. It requires that the WWW::Mechanize
17 object implements a corresponding C<< ->xpath >> method, as L<WWW::Mechanize::Firefox>
18 and L<WWW::Mechanize::PhantomJS> do.
19  
20 =head1 ADDED METHODS
21  
22 =head2 C<< $mech->selector( $css_selector, %options ) >>
23  
24 my @text = $mech->selector('p.content');
25  
26 Returns all nodes matching the given CSS selector. If
27 C<$css_selector> is an array reference, it returns
28 all nodes matched by any of the CSS selectors in the array.
29  
30 This takes the same options that C<< ->xpath >> does.
31  
32 =cut
33  
34 sub selector {
35 0 ▶ my ($self,$query,%options) = @_;
Subroutine selector: not called CC=5 SCAR=34.0
Pod documented
36 0 ▶ $options{ user_info } ||= "CSS selector '$query'";
Condition0%0/2
$options{"user_info"} ||= "CSS selector '${query}'"
l!l
00
MC/DC0%0/1
$options{"user_info"} ||= "CSS selector '${query}'"
$options{"user_info"}
Truth table0%0/2
A
A= $options{"user_info"}
Aresult
11
00
37 0 ▶ if ('ARRAY' ne (ref $query || '')) {
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" ne (ref $query || "")) 0 0 0
Condition0%0/2
ref $query || ''
l!l
00
MC/DC0%0/1
ref $query || ''
ref $query
Truth table0%0/2
A
A= ref $query
Aresult
11
00
38 0 $query = [$query];
39 };
40 0 ▶ my $root = $options{ node } ? './' : '';
Branch: 1 branch
BranchTrueFalseTotal
$options{'node'} ? : 0 0 0
41 0 my @q = map { selector_to_xpath($_, root => $root) } @$query;
42 0 $self->xpath(\@q, %options);
43 };
44  
45 1 1;
46  
47 =head1 USE IN YOUR MODULE
48  
49 If you are not using L<WWW::Mechanize::Pluggable>, you can import this
50 code in your module via the following:
51  
52 use WWW::Mechanize::Plugin::Selector;
53 {
54 no warnings 'once';
55 *selector = \&WWW::Mechanize::Plugin::Selector::selector;
56 }
57  
58 =head1 REPOSITORY
59  
60 The public repository of this module is
61 L<https://github.com/Corion/www-mechanize-plugin-selector>.
62  
63 =head1 SUPPORT
64  
65 The public support forum of this module is
66 L<https://perlmonks.org/>.
67  
68 =head1 BUG TRACKER
69  
70 Please report bugs in this module via the RT CPAN bug queue at
71 L<https://rt.cpan.org/Public/Dist/Display.html?Name=WWW-Mechanize-Plugin-Selector>
72 or via mail to L<www-mechanize-plugin-selector-Bugs@rt.cpan.org>.
73  
74 =head1 AUTHOR
75  
76 Max Maischein C<corion@cpan.org>
77  
78 =head1 COPYRIGHT (c)
79  
80 Copyright 2010-2017 by Max Maischein C<corion@cpan.org>.
81  
82 =head1 LICENSE
83  
84 This module is released under the same terms as Perl itself.
85  
86 =cut
↑ Summary