POE::Component::WWW::Google::PageRank - A non-blocking wrapper for WWW::Google::PageRank
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; }
Module is a simple non-blocking POE wrapper around WWW::Google::PageRank
my $poco = POE::Component::WWW::Google::PageRank->spawn; POE::Component::WWW::Google::PageRank->spawn( alias => 'ranker' );
Returns a PoCo object. Takes three optional arguments:
POE::Component::WWW::Google::PageRank->spawn( alias => 'ranker' );
Specifies a POE Kernel alias for the component
POE::Component::WWW::Google::PageRank->spawn( options => { trace => 1, default => 1, }, );
A hashref of POE Session options to pass to the component's session.
POE::Component::WWW::Google::PageRank->spawn( debug => 1 );
When set to a true value turns on output of debug messages.
These are the object-oriented methods of the components.
$poco->rank( { page => 'http://zoffix.com', event => 'got_rank', } );
Takes hashref of options. See rank event below for description.
rank
my $ranker_id = $poco->session_id;
Takes no arguments. Returns component's session ID.
$poco->shutdown;
Takes no arguments. Shuts down the component.
$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 => 'http://zoffix.com' }
Mandatory. The page for which we need to get the rank.
{ event => 'got_rank' }
Mandatory. An event to send the result to.
{ 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 => { 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.
new()
Optional. Any keys starting with _ (underscore) will not affect the component and will be passed back in the result intact.
_
$poe_kernel->post( ranker => 'shutdown' );
Takes no arguments. Tells the component to shut itself down.
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
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 occurred it will be undefined and error key will also be present.
$result->{page}
error
if ( $result->{error} ) { print "Error while fetching :( $result->{error}\n"; } else { print "Rank: $result->{rank}\n"; }
If an error occurred during the query the error key will be present with LWP::UserAgent status_line()'s message.
status_line()
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.
print "$result->{_name}, the answer is $result->{out}\n";
Any arguments beginning with _ (underscore) passed into the rank event/method will be present intact in the result.
Fork this module on GitHub: https://github.com/zoffixznet/POE-Component-Bundle-WebDevelopment
To report bugs or request features, please use https://github.com/zoffixznet/POE-Component-Bundle-WebDevelopment/issues
If you can't access GitHub, you can email your request to bug-POE-Component-Bundle-WebDevelopment at rt.cpan.org
bug-POE-Component-Bundle-WebDevelopment at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install POE::Component::Bundle::WebDevelopment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::Bundle::WebDevelopment
CPAN shell
perl -MCPAN -e shell install POE::Component::Bundle::WebDevelopment
For more information on module installation, please visit the detailed CPAN module installation guide.