NAME

AnyEvent::Google::PageRank - Non-blocking wrapper for WWW::Google::PageRank

SYNOPSIS

Object-oriented interface
use AnyEvent::Google::PageRank;
use AnyEvent;

my @urls = qw(http://perl.org http://cpan.org http://perlmonks.org);
my $rank = AnyEvent::Google::PageRank->new(
	timeout => 10,
	proxy   => 'localhost:3128'
);

my $cv = AnyEvent->condvar;
$cv->begin for @urls;

foreach my $url (@urls) {
	$rank->get($url, sub {
		my ($rank, $headers) = @_;
		print "$url - ", defined($rank) ? $rank : "fail: $headers->{Status} - $headers->{Reason}", "\n";
		$cv->end;
	});
}

$cv->recv;
Procedural interface
use AnyEvent::Google::PageRank qw(rank_get);
use AnyEvent;

my @urls = qw(http://perl.org http://cpan.org http://perlmonks.org);
my $cv = AnyEvent->condvar;
$cv->begin for @urls;

foreach my $url (@urls) {
	rank_get $url, timeout => 10, proxy => 'localhost:3128', sub {
		my ($rank, $headers) = @_;
		print "$url - ", defined($rank) ? $rank : "fail: $headers->{Status} - $headers->{Reason}", "\n";
		$cv->end;
	};
}

$cv->recv;

CAUTION

In 2016 Google officially closed public PageRank service. So, this module no longer works.

DESCRIPTION

AnyEvent::Google::PageRank helps to get google pagerank for specified url, like WWW::Google::PageRank does. But in contrast to WWW::Google::PageRank you can perform many requests in parallel. This module uses AnyEvent::HTTP as HTTP client.

EXPORT

rank_get() - on request

METHODS

new(%opts)

Creates new AnyEvent::Google::PageRank object. The following options available (all are optional):

KEY       DESCRIPTION                                DEFAULT
------------------------------------------------------------------
agent     User-Agent value in the headers            Mozilla/4.0 (compatible; GoogleToolbar 2.0.111-big; Windows XP 5.1)
proxy     http proxy as address:port                 undef
timeout   timeout for network operations             AnyEvent::HTTP default timeout
host      host for query                             toolbarqueries.google.com
ae_http   AnyEvent::HTTP request options as hashref  undef

get($url, $cb->($rank, $headers))

Get rank for specified url and call specified callback on finish. Parameters for callback are: rank and headers. On fail rank will be undef and reason could be found in $headers->{Reason}, code in $headers->{Status}. Special codes provided by this module are:

695 - malformed url

For other codes see AnyEvent::HTTP

FUNCTIONS

rank_get($url, key => val, ..., $cb->($rank, $headers))

Get rank for specified url and call specified callback on finish. Key/value pairs are options understanded by AnyEvent::HTTP::http_request() and new() method of this module (except ae_http option). For $cb description see get() method.

BUGS

Not a bug: don't forget to set $AnyEvent::HTTP::MAX_PER_HOST to proper value. See AnyEvent::HTTP for details.

If you find any bug, please report.

SEE ALSO

WWW::Google::PageRank, AnyEvent::HTTP

COPYRIGHT

Copyright Oleg G <oleg@cpan.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.