blib/lib/Bot/BasicBot/Pluggable/Module/WebSearch.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 CC 8 SCAR 38.1
CC
8
Cov
0%
said
72.0
help
2.0
BEGIN
2.0
CRAP 45.1
1 package Bot::BasicBot::Pluggable::Module::Search;
2  
3 use strict;
4 use Bot::BasicBot::Pluggable::Module;
5 use base qw(Bot::BasicBot::Pluggable::Module);
6  
7 use WWW::Search;
8  
9 sub said {
10 my ($self, $mess, $pri) = @_;
11  
12 my $phrase = $mess->{body};
13 my $who = $mess->{who};
14  
15 return unless ($pri == 2);
16  
17 my $engine;
18  
19 return unless ($phrase =~ s!search(?: using ([\w\:]+))?(?: for)? !$engine = ucfirst($1) || 'Yahoo';""!ei);
20  
21 return "Need something to search with!" if $phrase =~ m!^\s*$!;
22
23 my %engines = map { $_ => 1 } WWW::Search::installed_engines;
24 return "We don't have the engine installed for $engine, sorry" unless $engines{$engine};
25  
26 my $search = WWW::Search->new($engine);
27 my $query = WWW::Search::escape_query($phrase);
28 $search->native_query($query);
29  
30 my $result;
31 my $count = 0;
32 while (my $r = $search->next_result()) {
33 if ($result) {
34 $result .= " or ".$r->url();
35 } else {
36 $result = $r->url();
37 }
38 last if ++$count >= 3;
39 }
40  
41 return "Sorry, no results" unless $count;
42 return $result;
43  
44 }
45  
46 sub help {
47 return "Commands: 'search [using <engine>] [for] <phrase>";
48 }
49  
50 1;
51  
52 =head1 NAME
53  
54 Bot::BasicBot::Pluggable::Module::Search - web search interface
55  
56 =head1 SYNOPSIS
57  
58 Does exactly what it says on the tin; looks up things in web search
59 engines and brings you back the results.
60  
61  
62 =head1 IRC USAGE
63  
64  
65 [search] <engine> for <entry>
66  
67 Where E<lt>C<engine>E<gt> is one of
68  
69 AltaVista Dejanews Excite Gopher HotBot Infoseek
70 Lycos Magellan PLweb SFgate Simple Verity Google
71  
72  
73 =head1 AUTHOR
74  
75 Simon Wistow, <simon@thegestalt.org>
76  
77 based on code by Simon <simon@brecon.co.uk> and Kevin Lenzo <lenzo@cs.cmu.edu>
78  
79 =head1 COPYRIGHT
80  
81 Copyright 2005, Simon Wistow
82  
83 Distributed under the same terms as Perl itself.
84  
85 =head1 SEE ALSO
86  
87  
88 =cut
89