File Coverage

blib/lib/OurNet/Query.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             # $File: //depot/OurNet-Query/Query.pm $ $Author: autrijus $
2             # $Revision: #4 $ $Change: 1925 $ $DateTime: 2001/09/28 15:12:40 $
3              
4             package OurNet::Query;
5             require 5.005;
6              
7             $OurNet::Query::VERSION = '1.56';
8              
9 1     1   6938 use strict;
  1         1  
  1         33  
10              
11 1     1   497 use OurNet::Site;
  1         3  
  1         27  
12 1     1   866 use HTTP::Request::Common;
  1         50573  
  1         115  
13 1     1   1791 use LWP::Parallel::UserAgent;
  0            
  0            
14              
15             =head1 NAME
16              
17             OurNet::Query - Scriptable queries with template extraction
18              
19             =head1 SYNOPSIS
20              
21             use OurNet::Query;
22              
23             # Set query parameters
24             my ($query, $hits) = ('autrijus', 10);
25             my @sites = ('google', 'google'); # XXX: write more templates!
26             my %found;
27              
28             # Generate a new Query object
29             my $bot = OurNet::Query->new($query, $hits, @sites);
30              
31             # Perform a query
32             my $found = $bot->begin(\&callback, 30); # Timeout after 30 seconds
33              
34             print '*** ' . ($found ? $found : 'No') . ' match(es) found.';
35              
36             sub callback {
37             my %entry = @_;
38             my $entry = \%entry;
39              
40             unless ($found{$entry{url}}) {
41             print "*** [$entry->{title}]" .
42             " ($entry->{score})" .
43             " - [$entry->{id}]\n" .
44             " URL: [$entry->{url}]\n";
45             }
46              
47             $found{$entry{url}}++;
48             }
49              
50             =head1 DESCRIPTION
51              
52             This module provides an easy interface to perform multiple queries
53             to internet services, and I them into your own format at once.
54             The results are processed on-the-fly and are returned via callback
55             functions.
56              
57             Its interfaces resembles that of I's, but implements it
58             in a different fashion. While I relies on additional
59             subclasses to parse returned results, I uses I
60             descriptors> for search search engine, which makes it much easier
61             to add new backends.
62              
63             Site descriptors may be written in XML, I