Why not adopt me?
NAME
POE::Component::WWW::Google::PageRank - A non-blocking wrapper for WWW::Google::PageRank
SYNOPSIS
use strict;
use warnings;
use POE qw(Component::WWW::Google::PageRank);
my $poco
= POE::Component::WWW::Google::PageRank->spawn( alias => 'ranker' );
POE::Session->create(
package_states => [
'main' => [
qw( _start got_rank )
],
],
);
$poe_kernel->run;
sub _start {
$poe_kernel->post( ranker => rank => {
page => 'http://zoffix.com',
event => 'got_rank',
_random => 'foos',
}
);
}
sub got_rank {
my ( $kernel, $result ) = @_[ KERNEL, ARG0 ];
if ( $result->{error} ) {
print "ZOMG! An error: $result->{error}\n";
}
else {
print "The rank for $result->{page} is $result->{rank}\n";
}
print "Oh, BTW: $result->{_random}\n";
$poco->shutdown;
}
DESCRIPTION
Module is a simple non-blocking POE wrapper around WWW::Google::PageRank
CONSTRUCTOR
my $poco = POE::Component::WWW::Google::PageRank->spawn;
POE::Component::WWW::Google::PageRank->spawn( alias => 'ranker' );
Takes three optional arguments:
alias
POE::Component::WWW::Google::PageRank->spawn( alias => 'ranker' );
Specifies a POE Kernel alias for the component
options
POE::Component::WWW::Google::PageRank->spawn(
options => {
trace => 1,
default => 1,
},
);
A hashref of POE Session options to pass to the component's session.
debug
POE::Component::WWW::Google::PageRank->spawn( debug => 1 );
When set to a true value turns on output of debug messages.
METHODS
These are the object-oriented methods of the components.
rank
$poco->rank( {
page => 'http://zoffix.com',
event => 'got_rank',
}
);
Takes hashref of options. See rank
event below for description.
session_id
my $ranker_id = $poco->session_id;
Takes no arguments. Returns component's session ID.
shutdown
$poco->shutdown;
Takes no arguments. Shuts down the component.
ACEPTED EVENTS
rank
$poe_kernel->post( ranker => rank => {
page => 'http://zoffix.com',
event => 'got_rank',
session => $some_other_session,
_random => 'foos',
options => {
ua => 'Better not touch this',
timeout => 10,
}
}
);
Instructs the component to get a page rank. Options are passed in a hashref with keys as follows:
page
{ page => 'http://zoffix.com' }
Mandatory. The page for which we need to get the rank.
event
{ event => 'got_rank' }
Mandatory. An event to send the result to.
session
{ session => $some_other_session_ref }
{ session => 'some_alias' }
{ session => $session->ID }
Optional. An alternative session alias, reference or ID that the response should be sent to, defaults to sending session.
options
{ options => { timeout => 10 } }
Optional. The value must be a hashref and these options will go directly to WWW::Google::PageRank new()
method. See documentation for WWW::Google::PageRank for more information.
user defined
Optional. Any keys starting with _
(underscore) will not affect the component and will be passed back in the result intact.
shutdown
$poe_kernel->post( ranker => 'shutdown' );
Takes no arguments. Tells the component to shut itself down.
OUTPUT
sub got_rank {
my ( $kernel, $result ) = @_[ KERNEL, ARG0 ];
if ( $result->{error} ) {
print "ZOMG! An error: $result->{error}\n";
}
else {
print "The rank for $result->{page} is $result->{rank}\n";
}
print "Oh, BTW: $result->{_random}\n";
$poco->shutdown;
}
The result will be posted to the event and (optional) session specified in the arguments to the rank
(event or method). The result, in the form of a hashref, will be passed in ARG0. The keys of that hashref are as follows
rank
print "Rank is: $result->{rank}\n";
The rank
key will contain the page rank of the page passed to rank
event/method (note that the page is also in $result->{page}
). If an error occured it will be undefined and error
key will also be present.
error
if ( $result->{error} ) {
print "Error while fetching :( $result->{error}\n";
}
else {
print "Rank: $result->{rank}\n";
}
If an error occured during the query the error
key will be present with LWP::UserAgent status_line()
's message.
response
print "The status of request: " .
$result->{response}->status_line . "\n";
This key contains an HTTP::Response object returned by LWP::UserAgent when we were fetching for page rank.
user defined
print "$result->{_name}, the answer is $result->{out}\n";
Any arguments beginning with _
(underscore) passed into the calc
event/method will be present intact in the result.
PREREQUISITES
Needs POE and WWW::Google::PageRank
BUGS
None that I know of.
SEE ALSO
AUTHOR
Zoffix Znet, <zoffix@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Zoffix Znet
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.