| WWW-Google-Images documentation | Contained in the WWW-Google-Images distribution. |
WWW::Google::Images::SearchResult - Search result object for WWW::Google::Images
Creates and returns a new WWW::Google::Images::SearchResult object.
Returns the next image from result as a WWW::Google::Images::Image object.
Save all the image files and web pages from result.
Optional parameters:
Content is saved by calling $image->save_content() for each result.
Context is saved by calling $image->save_context() for each result.
A summary is created, that links saved files to original URLs.
Passed to $image->save_content() and $image->save_context().
Passed to $image->save_content() and $image->save_context().
Passed to $image->save_content() and $image->save_context().
Additionaly, if optional parameter file or base is given, an index number is automatically appended.
Copyright (C) 2004-2006, INRIA.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Guillaume Rousse <grousse@cpan.org>
| WWW-Google-Images documentation | Contained in the WWW-Google-Images distribution. |
# $Id: SearchResult.pm,v 1.8 2006/08/22 13:03:13 rousse Exp $ package WWW::Google::Images::SearchResult;
use WWW::Google::Images::Image; use File::Basename; use File::Path; use Carp; use strict;
sub new { my ($class, $agent, @urls) = @_; my $self = bless { _agent => $agent, _urls => \@urls }, $class; return $self; }
sub next { my ($self) = @_; my $url = shift @{$self->{_urls}}; return unless $url; return WWW::Google::Images::Image->new( $self->{_agent}, $url->{content}, $url->{context} ); }
sub save_all { my ($self, %args) = @_; if ($args{summary}) { my $dir = $args{dir} ? $args{dir} : '.'; mkpath($dir) unless -d $dir; open(SUMMARY, ">$dir/summary.txt") or carp "unable to open file $dir/summary.txt for writing: $!\n"; } my $count; while (my $image = $self->next()) { $count++; my ($content, $context); $content = $image->save_content( dir => $args{dir} ? $args{dir} : undef, file => $args{file} ? $args{file} . $count : undef, base => $args{base} ? $args{base} . $count : undef, ) if $args{content}; $context = $image->save_context( dir => $args{dir} ? $args{dir} : undef, file => $args{file} ? $args{file} . $count : undef, base => $args{base} ? $args{base} . $count : undef, ) if $args{context}; if ($args{summary}) { print SUMMARY basename($content) . "\t" . $image->content_url() . "\n" if $args{content}; print SUMMARY basename($context) . "\t" . $image->context_url() . "\n" if $args{context}; } } if ($args{summary}) { close(SUMMARY); } }
1;