| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | croak("Unknown option") unless $_ eq 'ism' || $_ eq 'type'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ eq "ism" or $_ eq "type"
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"
| |||||||||||||||||||||||||||||
| 43 | 2 | my %dict = qw/who 1 what 2 where 3 when 4/; | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | if( $_ eq 'type' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | croak("Invalid type") unless $dict{$options_ref->{'type'}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||