Debian Codegraph @

googlism/Googlism.pm

raw
1 package WWW::Search::Googlism;
2
3 use 5.006;
4 use strict;
5 use warnings;
6 require Exporter;
7 our @ISA = qw(WWW::Search Exporter);
8 our $VERSION = '0.02';
9 use Carp;
10 use WWW::Search qw/generic_option/;
11 require WWW::SearchResult;
12
13 my $MAINTAINER = 'xern <[email protected]>';
14
15 sub native_setup_search {
16 my($self, $native_query, $native_options_ref) = @_;
17 $self->{_debug} = $native_options_ref->{'search_debug'};
18 $self->{_debug} = 0 if (!defined($self->{_debug}));
19 $self->{agent_e_mail} = '[email protected]';
20 $self->user_agent('WWW::Search::Googlism Agent');
21 $self->{_next_to_retrieve} = 1;
22 $self->{'_num_hits'} = 0;
23
24 if (!defined($self->{_options})) {
25 $self->{'search_base_url'} = 'http://www.googlism.com/';
26 $self->{_options} = {
27 'search_url' => 'http://www.googlism.com/index.htm',
28 'ism' => $native_query,
29 };
30 }
31 my $options_ref = $self->{_options};
32 if (defined($native_options_ref)){
33 foreach (keys %$native_options_ref)
34 {
35 $options_ref->{$_} = $native_options_ref->{$_};
36 }
37 }
38 my($options) = '';
39 foreach (sort keys %$options_ref)
40 {
41 next if (generic_option($_));
42 croak("Unknown option") unless $_ eq 'ism' || $_ eq 'type';
43 my %dict = qw/who 1 what 2 where 3 when 4/;
44 if( $_ eq 'type' ){
45 croak("Invalid type") unless $dict{$options_ref->{'type'}};
46 $options_ref->{'type'} = $dict{$options_ref->{'type'}};
47 }
48 $options .= $_ . '=' . $options_ref->{$_} . '&';
49 }
50 chop $options;
51 $self->{_next_url} = $self->{_options}{'search_url'}.'?'.$options;
52 # print $self->{_next_url};
53 }
54
55 sub native_retrieve_some {
56 my ($self) = @_;
57 return unless $self->{_next_url};
58 my($response) = $self->http_request('GET', $self->{_next_url});
59 $self->{response} = $response;
60 $response->{_content} =~ m!<br><h1><span class="suffix">Googlism for:</span> .+?</h1><br>(.+)<br>\n!s;
61 for my $r (split /<br>\n/, $1){
62 $self->{_num_hits}++;
63 push @{$self->{cache}}, $r;
64 }
65
66 undef $self->{_next_url};
67 }
68
69 1;
70 __END__
71 # Below is stub documentation for your module. You better edit it!
72
73 =head1 NAME
74
75 WWW::Search::Googlism - Searching Googlism
76
77 =head1 SYNOPSIS
78
79 use WWW::Search::Googlism;
80 $query = "googlism";
81 $search = new WWW::Search('Googlism');
82 $search->native_query(WWW::Search::escape_query($query), { type => 'who' });
83 while (my $result = $search->next_result()) {
84 print "$result\n";
85 }
86
87
88 =head1 DESCRIPTION
89
90 WWW::Search::Googlism is a subclass of WWW::Search. Users can use this module to search http://www.googlism.com/.
91
92 See also L<bin/googlism.pl> distributed with this module.
93
94 =head1 TYPES
95
96 Four types of searching Googlism are "who is", "what is", "where is", and "when is". Specify it with parameter 'type'.
97
98 =head1 AUTHOR
99
100 xern <[email protected]>
101
102 =head1 LICENSE
103
104 Released under The Artistic License
105
106 =head1 SEE ALSO
107
108 L<WWW::Search>, L<bin/googlism.pl>
109
110 =cut