Debian Codegraph @

lib/WWW/Search/Null/Count.pm

raw
1
2 # $Id: Count.pm,v 1.17 2010-12-02 23:45:57 Martin Exp $
3
4 =head1 NAME
5
6 WWW::Search::Null::Count - class for testing WWW::Search clients
7
8 =head1 SYNOPSIS
9
10 use WWW::Search;
11 my $iCount = 4;
12 my $oSearch = new WWW::Search('Null::Count',
13 '_null_count' => $iCount,
14 );
15 $oSearch->native_query('Makes no difference what you search for...');
16 my @aoResults = $oSearch->results;
17 # ...You get $iCount results.
18
19 =head1 DESCRIPTION
20
21 This class is a specialization of WWW::Search that returns some hits,
22 but no error message. The number of hits returned can be controlled
23 by adding a '_null_count' hash entry onto the call to
24 WWW::Search::new(). The default is 5.
25
26 This module might be useful for testing a client program without
27 actually being connected to any particular search engine.
28
29 =head1 AUTHOR
30
31 Martin 'Kingpin' Thurn, C<mthurn at cpan.org>, L<http://tinyurl.com/nn67z>.
32
33 =cut
34
35 package WWW::Search::Null::Count;
36
37 use strict;
38 use warnings;
39
40 use WWW::Search;
41 use WWW::Search::Result;
42
43 use base 'WWW::Search';
44 our
45 $VERSION = do { my @r = (q$Revision: 1.17 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
46 our $MAINTAINER = q{Martin Thurn <[email protected]>};
47
48 use constant DEBUG_FUNC => 0;
49
50 sub _native_setup_search
51 {
52 my ($self, $native_query, $native_opt) = @_;
53 # print STDERR " FFF ::Null::Count::_native_setup_search()\n" if (DEBUG_FUNC || $self->{_debug});
54 if (! defined $self->{_null_count})
55 {
56 # print STDERR " + setting default _null_count to 5\n";
57 $self->{_null_count} = 5;
58 } # if
59 $self->{_allow_empty_query} = 1;
60 } # _native_setup_search
61
62
63 sub _native_retrieve_some
64 {
65 my $self = shift;
66 # print STDERR " FFF ::Null::Count::_n_r_s()\n" if (DEBUG_FUNC || $self->{_debug});
67 my $response = new HTTP::Response(200,
68 "This is a test of WWW::Search");
69 $self->{response} = $response;
70 my $iCount = $self->{_null_count};
71 # print STDERR " + iCount is $iCount\n";
72 $self->_elem('approx_count', $iCount);
73 for my $i (1..$iCount)
74 {
75 my $oResult = new WWW::Search::Result;
76 $oResult->url(qq{url$i});
77 $oResult->title(qq{title$i});
78 $oResult->description("description$i");
79 $oResult->change_date("yesterday");
80 $oResult->index_date("today");
81 $oResult->raw(qq{<A HREF="url$i">});
82 $oResult->score(100-$i*2);
83 $oResult->normalized_score(1000-$i*20);
84 $oResult->size($i*2*1024);
85 $oResult->source('WWW::Search::Null::Count');
86 $oResult->company('Dub Dub Dub Search, Inc.');
87 $oResult->location('Ashburn, VA');
88 if ($i % 2)
89 {
90 $oResult->urls("url$i", map { "url$i.$_" } (1..$iCount));
91 $oResult->related_urls(map { "url-r$i.$_" } (1..$iCount));
92 my @aoTitles = map { "title-r$i.$_" } (1..$iCount);
93 $oResult->related_titles(\@aoTitles);
94 }
95 else
96 {
97 for my $j (1..$iCount)
98 {
99 $oResult->add_url(qq{url$i.$j});
100 $oResult->add_related_url(qq{url-r$j});
101 $oResult->add_related_title(qq{title-r$i});
102 } # for $j
103 } # else
104 push(@{$self->{cache}}, $oResult);
105 } # for $i
106 return 0;
107 } # _native_retrieve_some
108
109 1;
110
111 __END__
112