The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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' );

Returns a PoCo object. 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.

ACCEPTED 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 occurred 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 occurred 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 rank event/method will be present intact in the result.

REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/POE-Component-Bundle-WebDevelopment

BUGS

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

AUTHOR

Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)

LICENSE

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.