lib/WWW/ImageSpool/Source/Google.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 94 CC 8 SCAR 27.8
CC
8
Cov
0%
agent_search
30.0
new
20.0
BEGIN
2.0
CRAP 16.1
1 #!perl
2  
3 package WWW::ImageSpool::Source::Google;
4  
5 use strict;
6 use warnings;
7 use WWW::ImageSpool::Source;
8 use base qw(WWW::ImageSpool::Source);
9 use vars qw($LIMIT $SEARCHLIMIT @EXPORT_OK);
10  
11 use WWW::Google::Images;
12  
13 @EXPORT_OK = qw($LIMIT);
14 $LIMIT = 5;
15 $SEARCHLIMIT = 50;
16 return 1;
17  
18 sub new
19 {
20 my $class = shift;
21 my %args = @_;
22 my %google_args;
23 my $self;
24
25 $google_args{server} = $args{server}
26 if($args{server});
27
28 $google_args{proxy} = $args{proxy}
29 if($args{proxy});
30  
31 $args{limit} ||= $LIMIT;
32 $args{searchlimit} ||= $SEARCHLIMIT;
33
34 if(my $agent = WWW::Google::Images->new(%google_args))
35 {
36 $self = bless { args => \%args, google_args => \%google_args, agent => $agent, urls => {} }, $class;
37 }
38 else
39 {
40 warn "WWW::ImageSpool::Sources::Google->new(): Failed to initialize WWW::Google::Images object!\n";
41 return;
42 }
43  
44 return $self;
45 }
46  
47 sub agent_search
48 {
49 my($self, $search, $searchlimit) = @_;
50 my $count = 0;
51  
52 if(!$search)
53 {
54 return;
55 }
56
57 if(!$searchlimit)
58 {
59 $searchlimit = $self->{args}->{searchlimit};
60 }
61
62 my $result = ($self->{agent}->search($search, limit => $searchlimit));
63 my @result;
64 my $image;
65  
66 while(($count < $searchlimit) && ($image = $result->next()))
67 {
68 my $url = $image->content_url();
69 push(@result, $image->content_url());
70 $count++;
71 }
72 if(scalar(@result))
73 {
74 if($self->{args}->{verbose} > 2)
75 {
76 print scalar(@result), "/$searchlimit results for $search.\n";
77 }
78 return(@result);
79 }
80 else
81 {
82 return;
83 }
84 }