blib/lib/WWW/Search/Lycos.pm

filter: Statementstmt 37.6% 38 / 101 Branchbran 13.1% 5 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 33.3% 1 / 3 totaltotal 33.1% 51 / 154 CC 23 SCAR 48.7
CC
23
Cov
31%
_parse_tree
272.0
native_setup_search
9.2
gui_query
2.0
CRAP 130.6
↑ Summary
1 # Lycos.pm
2 # by Wm. L. Scheding and Martin Thurn
3 # Copyright (C) 1996-1998 by USC/ISI
4 # $Id: Lycos.pm,v 2.223 2008/12/15 22:47:13 Martin Exp $
5  
6 =head1 NAME
7  
8 WWW::Search::Lycos - class for searching www.lycos.com
9  
10 =head1 SYNOPSIS
11  
12 use WWW::Search;
13 my $oSearch = new WWW::Search('Lycos');
14 my $sQuery = WWW::Search::escape_query("+sushi restaurant +Columbus Ohio");
15 $oSearch->native_query($sQuery);
16 while (my $oResult = $oSearch->next_result())
17 { print $oResult->url, "\n"; }
18  
19 =head1 DESCRIPTION
20  
21 This class is a Lycos specialization of L<WWW::Search>. It handles
22 making and interpreting Lycos-site searches F<http://www.lycos.com>.
23  
24 This class exports no public interface; all interaction should
25 be done through L<WWW::Search> objects.
26  
27 =head1 NOTES
28  
29 Warning! As of 2004-01, lycos.com often returns an error page in
30 place of the third page of results. So it is very difficult to get
31 more than 20 hits for any query!
32  
33 www.lycos.com is sometimes slow to respond; but I have not had a
34 problem with the default timeout.
35  
36 www.lycos.com does not give the date nor size of the pages at the
37 resulting URLs; therefore change_date() and size() will never have a
38 value.
39  
40 =head1 SEE ALSO
41  
42 To make new back-ends, see L<WWW::Search>.
43  
44 =head1 BUGS
45  
46 Please tell the author if you find any!
47  
48 =head1 AUTHOR
49  
50 As of 1998-12-07, C<WWW::Search::Lycos> is maintained by Martin Thurn
51 (mthurn@cpan.org).
52  
53 C<WWW::Search::Lycos> was originally written by Martin Thurn,
54 based on C<WWW::Search::Yahoo> version 1.12 of 1998-10-22.
55  
56 =head1 LEGALESE
57  
58 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
59 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
60 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
61  
62 =cut
63  
64 #####################################################################
65  
66 package WWW::Search::Lycos;
67  
68 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 my
72 1 $VERSION = 2.225;
73 1 our $MAINTAINER = 'Martin Thurn <mthurn@cpan.org>';
74  
75 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 1 ▶use base 'WWW::Search';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 1 ▶use WWW::Search::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 sub gui_query
81 0 ▶ {
Subroutine gui_query: not called CC=1 SCAR=6.9
Pod documented
82 0 my $self = shift;
83 0 my $sQuery = shift;
84 $self->{_options} = {
85 0 search_url => q{http://search.lycos.com/},
86 query => $sQuery,
87 };
88 0 return $self->native_query(@_);
89 } # gui_query
90  
91  
92 sub native_setup_search
93 3 ▶ {
Subroutine native_setup_search: called CC=8 SCAR=22.2
Pod undocumented
94 3 my ($self, $native_query, $native_options_ref) = @_;
95 3 $self->{_debug} = $native_options_ref->{'search_debug'};
96 3 ▶ $self->{_debug} = 2 if ($native_options_ref->{'search_parse_debug'});
Branch: 1 branch
BranchTrueFalseTotal
if $native_options_ref->{"search_parse_debug"} 0 3 3
97 3 ▶ $self->{_debug} = 0 if (!defined($self->{_debug}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_debug"} 0 3 3
98  
99 # lycos.com returns 10 hits per page no matter what.
100 3 $self->{'_hits_per_page'} = 10;
101  
102 # $self->{agent_e_mail} = 'mthurn@cpan.org';
103 3 $self->user_agent('non-robot');
104  
105 3 $self->{_next_to_retrieve} = 1;
106 3 $self->{'_num_hits'} = 0;
107  
108 3 ▶ if (! defined($self->{_options}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_options"}) 3 0 3
109 {
110 3 $self->{'search_base_url'} = 'http://search.lycos.com';
111 $self->{_options} = {
112 3 'search_url' => $self->{'search_base_url'} .'/web/',
113 'q' => $native_query,
114 # 'loc' => 'searchbox',
115 # 'tab' => 'web',
116 };
117 } # if
118  
119 3 my $options_ref = $self->{_options};
120  
121 # Copy in options which were passed in our second argument:
122 3 ▶ if (defined($native_options_ref))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native_options_ref) 3 0 3
123 {
124 3 foreach (keys %$native_options_ref)
125 {
126 3 $options_ref->{$_} = $native_options_ref->{$_};
127 } # foreach
128 } # if
129  
130 # Copy in options which were set by a child object:
131 3 ▶ if (defined($self->{'_child_options'}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_child_options"}) 0 3 3
132 {
133 0 foreach (keys %{$self->{'_child_options'}})
134 {
135 0 $self->{'_options'}->{$_} = $self->{'_child_options'}->{$_};
136 } # foreach
137 } # if
138  
139 # Finally figure out the url.
140 3 $self->{_next_url} = $self->{_options}{'search_url'} .'?'. $self->hash_to_cgi_string($self->{_options});
141 } # native_setup_search
142  
143  
144 sub preprocess_results_page_OFF
145 0 ▶ {
Subroutine preprocess_results_page_OFF: not called CC=1 SCAR=6.9
Pod undocumented
146 0 my $self = shift;
147 0 my $sPage = shift;
148 0 print STDERR '='x 10, $sPage, '='x 10, "\n";
149 0 return $sPage;
150 } # preprocess_results_page
151  
152  
153 sub _parse_tree
154 0 ▶ {
Subroutine _parse_tree: not called CC=16 SCAR=56.1
155 0 my $self = shift;
156 0 my $oTree = shift;
157 0 ▶ warn " DDD start Lycos::_parse_tree()\n" if (3 <= $self->{_debug});
Branch: 1 branch
BranchTrueFalseTotal
if 3 <= $self->{"_debug"} 0 0 0
158 0 my $hits_found = 0;
159 0 ▶ unless ($self->approximate_result_count)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->approximate_result_count) 0 0 0
160 {
161 0 my $oTITLE = $oTree->look_down(
162 _tag => 'div',
163 class => 'search-numbers',
164 );
165 0 ▶ if (ref $oTITLE)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $oTITLE) 0 0 0
166 {
167 0 my $sRC = $oTITLE->parent->as_text;
168 0 ▶ warn " DDD RC == $sRC\n" if 2 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 <= $self->{"_debug"} 0 0 0
169 0 ▶ if ($sRC =~ m!\b([0-9,]+)\s*results\b!i)
Branch: 1 branch
BranchTrueFalseTotal
if ($sRC =~ /\b([0-9,]+)\s*results\b/i) 0 0 0
170 {
171 0 my $sCount = $1;
172 0 ▶ warn " DDD raw count == $sCount\n" if 3 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 3 <= $self->{"_debug"} 0 0 0
173 0 $sCount =~ s!,!!g;
174 0 ▶ warn " DDD cooked count == $sCount\n" if 3 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 3 <= $self->{"_debug"} 0 0 0
175 0 $self->approximate_result_count($sCount);
176 } # if
177 } # if
178 } # unless
179 0 my ($sURL, $sTitle, $sDesc);
180 0 my $sScore = '';
181 0 my $sSize = '';
182 0 my $sDate = '';
183 0 my @aoIS = $oTree->look_down(_tag => 'h2',
184 class => 'result-title',
185 );
186 IS_TAG:
187 0 foreach my $oIS (@aoIS)
188 {
189 0 ▶ next IS_TAG unless ref $oIS;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oIS 0 0 0
190 0 ▶ warn " DDD oIS is ===". $oIS->as_HTML ."===\n" if 2 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 <= $self->{"_debug"} 0 0 0
191 0 my $sTitle = $oIS->as_text;
192  
193 0 my $oTDhit = $oIS->parent;
194 0 ▶ next IS_TAG unless ref $oTDhit;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oTDhit 0 0 0
195 0 ▶ warn " DDD oTDhit is ===". $oTDhit->as_HTML ."===\n" if 2 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 <= $self->{"_debug"} 0 0 0
196 0 my $oSPAN = $oTDhit->look_down(_tag => 'span',
197 class => 'result-url');
198 0 my $sURL = 'http://'. $oSPAN->as_text;
199 0 $oSPAN = $oTDhit->look_down(_tag => 'span',
200 class => 'result-description');
201 0 my $sDesc = $oSPAN->as_text;
202 0 ▶ warn " DDD found desc ===$sDesc===\n" if 2 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 <= $self->{"_debug"} 0 0 0
203  
204 0 my $hit = new WWW::Search::Result;
205 0 $hit->add_url($sURL);
206 0 $hit->title($sTitle);
207 0 $hit->description(_strip($sDesc));
208 0 push(@{$self->{cache}}, $hit);
209 0 $self->{'_num_hits'}++;
210 0 $hits_found++;
211 } # foreach $oB
212 # Find the next link, if any:
213 my @aoA = $oTree->look_down(_tag => 'a',
214 0 ▶ sub { $_[0]->as_text eq 'Next' } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
215 0 A_TAG:
216 # We want the last "next" link on the page:
217 my $oA = $aoA[-1];
218 0 ▶ if (ref $oA)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $oA) 0 0 0
219 {
220 0 ▶ warn " DDD oAnext is ===", $oA->as_HTML, "===\n" if 2 <= $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 <= $self->{"_debug"} 0 0 0
221 0 $self->{_next_url} = $self->absurl($self->{'_prev_url'}, $oA->attr('href'));
222 } # if
223 SKIP_NEXT_LINK:
224  
225 0 return $hits_found;
226 } # _parse_tree
227  
228  
229 sub _strip
230 0 ▶ {
Subroutine _strip: not called CC=1 SCAR=6.9
231 0 my $sRaw = shift;
232 0 my $s = &WWW::Search::strip_tags($sRaw);
233 # Strip leading whitespace:
234 0 $s =~ s!\A[\240\t\r\n\ ]+ !!x;
235 # Strip trailing whitespace:
236 0 $s =~ s! [\240\t\r\n\ ]+\Z!!x;
237 0 return $s;
238 } # _strip
239  
240 1 1;
241  
242 __END__
↑ Summary