| line | stmt | bran | cond | sub | pod | time | code | 
| 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, L. | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =cut | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | package WWW::Search::Null::Count; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 3 |  |  | 3 |  | 3130 | use strict; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 98 |  | 
| 38 | 3 |  |  | 3 |  | 20 | use warnings; | 
|  | 3 |  |  |  |  | 11 |  | 
|  | 3 |  |  |  |  | 77 |  | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 3 |  |  | 3 |  | 15 | use WWW::Search; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 128 |  | 
| 41 | 3 |  |  | 3 |  | 474 | use WWW::Search::Result; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 134 |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 3 |  |  | 3 |  | 20 | use base 'WWW::Search'; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 494 |  | 
| 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 }; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 3 |  |  | 3 |  | 23 | use constant DEBUG_FUNC => 0; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 1492 |  | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub _native_setup_search | 
| 51 |  |  |  |  |  |  | { | 
| 52 | 5 |  |  | 5 |  | 13 | my ($self, $native_query, $native_opt) = @_; | 
| 53 |  |  |  |  |  |  | # print STDERR " FFF ::Null::Count::_native_setup_search()\n" if (DEBUG_FUNC || $self->{_debug}); | 
| 54 | 5 | 100 |  |  |  | 15 | if (! defined $self->{_null_count}) | 
| 55 |  |  |  |  |  |  | { | 
| 56 |  |  |  |  |  |  | # print STDERR " +   setting default _null_count to 5\n"; | 
| 57 | 1 |  |  |  |  | 3 | $self->{_null_count} = 5; | 
| 58 |  |  |  |  |  |  | } # if | 
| 59 | 5 |  |  |  |  | 18 | $self->{_allow_empty_query} = 1; | 
| 60 |  |  |  |  |  |  | } # _native_setup_search | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub _native_retrieve_some | 
| 64 |  |  |  |  |  |  | { | 
| 65 | 3 |  |  | 3 |  | 6 | my $self = shift; | 
| 66 |  |  |  |  |  |  | # print STDERR " FFF ::Null::Count::_n_r_s()\n" if (DEBUG_FUNC || $self->{_debug}); | 
| 67 | 3 |  |  |  |  | 19 | my $response = new HTTP::Response(200, | 
| 68 |  |  |  |  |  |  | "This is a test of WWW::Search"); | 
| 69 | 3 |  |  |  |  | 176 | $self->{response} = $response; | 
| 70 | 3 |  |  |  |  | 4 | my $iCount = $self->{_null_count}; | 
| 71 |  |  |  |  |  |  | # print STDERR " +   iCount is $iCount\n"; | 
| 72 | 3 |  |  |  |  | 23 | $self->_elem('approx_count', $iCount); | 
| 73 | 3 |  |  |  |  | 34 | for my $i (1..$iCount) | 
| 74 |  |  |  |  |  |  | { | 
| 75 | 53 |  |  |  |  | 142 | my $oResult = new WWW::Search::Result; | 
| 76 | 53 |  |  |  |  | 186 | $oResult->url(qq{url$i}); | 
| 77 | 53 |  |  |  |  | 170 | $oResult->title(qq{title$i}); | 
| 78 | 53 |  |  |  |  | 517 | $oResult->description("description$i"); | 
| 79 | 53 |  |  |  |  | 442 | $oResult->change_date("yesterday"); | 
| 80 | 53 |  |  |  |  | 426 | $oResult->index_date("today"); | 
| 81 | 53 |  |  |  |  | 462 | $oResult->raw(qq{}); | 
| 82 | 53 |  |  |  |  | 449 | $oResult->score(100-$i*2); | 
| 83 | 53 |  |  |  |  | 424 | $oResult->normalized_score(1000-$i*20); | 
| 84 | 53 |  |  |  |  | 477 | $oResult->size($i*2*1024); | 
| 85 | 53 |  |  |  |  | 415 | $oResult->source('WWW::Search::Null::Count'); | 
| 86 | 53 |  |  |  |  | 413 | $oResult->company('Dub Dub Dub Search, Inc.'); | 
| 87 | 53 |  |  |  |  | 420 | $oResult->location('Ashburn, VA'); | 
| 88 | 53 | 100 |  |  |  | 474 | if ($i % 2) | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 27 |  |  |  |  | 135 | $oResult->urls("url$i", map { "url$i.$_" } (1..$iCount)); | 
|  | 991 |  |  |  |  | 2060 |  | 
| 91 | 27 |  |  |  |  | 136 | $oResult->related_urls(map { "url-r$i.$_" } (1..$iCount)); | 
|  | 991 |  |  |  |  | 1817 |  | 
| 92 | 27 |  |  |  |  | 128 | my @aoTitles = map { "title-r$i.$_" } (1..$iCount); | 
|  | 991 |  |  |  |  | 1838 |  | 
| 93 | 27 |  |  |  |  | 133 | $oResult->related_titles(\@aoTitles); | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | else | 
| 96 |  |  |  |  |  |  | { | 
| 97 | 26 |  |  |  |  | 55 | for my $j (1..$iCount) | 
| 98 |  |  |  |  |  |  | { | 
| 99 | 986 |  |  |  |  | 2857 | $oResult->add_url(qq{url$i.$j}); | 
| 100 | 986 |  |  |  |  | 2654 | $oResult->add_related_url(qq{url-r$j}); | 
| 101 | 986 |  |  |  |  | 2174 | $oResult->add_related_title(qq{title-r$i}); | 
| 102 |  |  |  |  |  |  | } # for $j | 
| 103 |  |  |  |  |  |  | } # else | 
| 104 | 53 |  |  |  |  | 107 | push(@{$self->{cache}}, $oResult); | 
|  | 53 |  |  |  |  | 133 |  | 
| 105 |  |  |  |  |  |  | } # for $i | 
| 106 | 3 |  |  |  |  | 26 | return 0; | 
| 107 |  |  |  |  |  |  | } # _native_retrieve_some | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | 1; | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | __END__ |