lib/WWW/Search/Googlism.pm

filter: Statementstmt 94.5% 52 / 55 Branchbran 62.5% 10 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 83.5% 71 / 85 CC 13 SCAR 20.0
CC
13
Cov
86%
native_setup_search
11.4
native_retrieve_some
3.3
BEGIN
1.0
CRAP 7.4
↑ Summary script/googlism.pl »
1 package WWW::Search::Googlism;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Exporter;
7 1 our @ISA = qw(WWW::Search Exporter);
8 1 our $VERSION = '0.02';
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use WWW::Search qw/generic_option/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 require WWW::SearchResult;
12  
13 1 my $MAINTAINER = 'xern <xern@cpan.org>';
14  
15 1 ▶sub native_setup_search {
Subroutine native_setup_search: called CC=11 SCAR=24.3
Pod undocumented
16 1 my($self, $native_query, $native_options_ref) = @_;
17 1 $self->{_debug} = $native_options_ref->{'search_debug'};
18 1 ▶ $self->{_debug} = 0 if (!defined($self->{_debug}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_debug"} 1 0 1
19 1 $self->{agent_e_mail} = 'xern@cpan.org';
20 1 $self->user_agent('WWW::Search::Googlism Agent');
21 1 $self->{_next_to_retrieve} = 1;
22 1 $self->{'_num_hits'} = 0;
23  
24 1 ▶ if (!defined($self->{_options})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_options"}) 1 0 1
25 1 $self->{'search_base_url'} = 'http://www.googlism.com/';
26 $self->{_options} = {
27 1 'search_url' => 'http://www.googlism.com/index.htm',
28 'ism' => $native_query,
29 };
30 }
31 1 my $options_ref = $self->{_options};
32 1 ▶ if (defined($native_options_ref)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native_options_ref) 1 0 1
33 1 foreach (keys %$native_options_ref)
34 {
35 1 $options_ref->{$_} = $native_options_ref->{$_};
36 }
37 }
38 1 my($options) = '';
39 1 foreach (sort keys %$options_ref)
40 {
41 3 ▶ next if (generic_option($_));
Branch: 1 branch
BranchTrueFalseTotal
if generic_option($_) 1 2 3
42 2 ▶ croak("Unknown option") unless $_ eq 'ism' || $_ eq 'type';
Branch: 1 branch
BranchTrueFalseTotal
unless $_ eq "ism" or $_ eq "type" 0 2 2
Condition66%2/3
$_ eq "ism" or $_ eq "type"
l!l&&r!l&&!r
110
MC/DC0%0/2
$_ eq "ism" or $_ eq "type"
$_ eq "ism" $_ eq "type"
Truth table66%2/3
A or B
A= $_ eq "ism"B= $_ eq "type"
ABresult
1X1
011
000
43 2 my %dict = qw/who 1 what 2 where 3 when 4/;
44 2 ▶ if( $_ eq 'type' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "type") 1 1 2
45 1 ▶ croak("Invalid type") unless $dict{$options_ref->{'type'}};
Branch: 1 branch
BranchTrueFalseTotal
unless $dict{$options_ref->{"type"}} 0 1 1
46 1 $options_ref->{'type'} = $dict{$options_ref->{'type'}};
47 }
48 2 $options .= $_ . '=' . $options_ref->{$_} . '&';
49 }
50 1 chop $options;
51 1 $self->{_next_url} = $self->{_options}{'search_url'}.'?'.$options;
52 # print $self->{_next_url};
53 }
54  
55 1 ▶sub native_retrieve_some {
Subroutine native_retrieve_some: called CC=3 SCAR=12.0
Pod undocumented
56 1 my ($self) = @_;
57 1 ▶ return unless $self->{_next_url};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_next_url"} 0 1 1
58 1 my($response) = $self->http_request('GET', $self->{_next_url});
59 1 $self->{response} = $response;
60 1 $response->{_content} =~ m!<br><h1><span class="suffix">Googlism for:</span> .+?</h1><br>(.+)<br>\n!s;
61 1 for my $r (split /<br>\n/, $1){
62 0 $self->{_num_hits}++;
63 0 push @{$self->{cache}}, $r;
64 }
65  
66 1 undef $self->{_next_url};
67 }
68  
69 1 1;
70 __END__
↑ Summary script/googlism.pl »