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

NAME

POE::Component::WWW::Pastebin::Many::Retrieve - non-blocking wrapper around WWW::Pastebin::Many::Retrieve

SYNOPSIS

    use strict;
    use warnings;

    use POE qw(Component::WWW::Pastebin::Many::Retrieve);

    my $poco = POE::Component::WWW::Pastebin::Many::Retrieve->spawn;

    POE::Session->create(
        package_states => [ main => [qw(_start retrieved)] ],
    );

    $poe_kernel->run;

    sub _start {
        $poco->retrieve( {
                uri     => 'http://phpfi.com/302683',
                event   => 'retrieved',
                _random => scalar localtime,
            }
        );
    }

    sub retrieved {
        my $in_ref = $_[ARG0];

        print "This is request from $in_ref->{_random}\n";

        if ( $in_ref->{error} ) {
            print "Got error: $in_ref->{error}\n";
        }
        else {
            print "Paste $in_ref->{uri} contains:\n$in_ref->{content}\n";
        }

        $poco->shutdown;
    }

Using event based interface is also possible.

DESCRIPTION

The module is a non-blocking wrapper around WWW::Pastebin::Many::Retrieve which provides interface to retrieve pastes from many different pastebin sites.

CONSTRUCTOR

spawn

    my $poco = POE::Component::WWW::Pastebin::Many::Retrieve->spawn;

    POE::Component::WWW::Pastebin::Many::Retrieve->spawn(
        alias => 'paster',
        timeout => 30,
        options => {
            debug => 1,
            trace => 1,
            # POE::Session arguments for the component
        },
        debug => 1, # output some debug info
    );

The spawn method returns a POE::Component::WWW::Pastebin::Many::Retrieve object. It takes a few arguments, all of which are optional. The possible arguments are as follows:

alias

    ->spawn( alias => 'paster' );

Optional. Specifies a POE Kernel alias for the component.

timeout

    ->spawn( timeout => 30 );

Optional. Specifies the network timeout to relate to when retrieving pastes. Defaults to: 30 seconds

options

    ->spawn(
        options => {
            trace => 1,
            default => 1,
        },
    );

Optional. A hashref of POE Session options to pass to the component's session.

debug

    ->spawn(
        debug => 1
    );

When set to a true value turns on output of debug messages. Defaults to: 0.

METHODS

retrieve

    $poco->retrieve( {
            event       => 'event_for_output',
            uri         => 'http://uri_to_paste_you_want_to_retrieve.com',
            _blah       => 'pooh!',
            session     => 'other',
        }
    );

Takes a hashref as an argument, does not return a sensible return value. See retrieve event's description for more information.

session_id

    my $poco_id = $poco->session_id;

Takes no arguments. Returns component's session ID.

shutdown

    $poco->shutdown;

Takes no arguments. Shuts down the component.

ACCEPTED EVENTS

retrieve

    $poe_kernel->post( paster => retrieve => {
            event       => 'event_for_output',
            uri         => 'http://uri_to_paste_you_want_to_retrieve.com',
            _blah       => 'pooh!',
            session     => 'other',
        }
    );

Instructs the component to retrieve a paste. Takes a hashref as an argument, the possible keys/value of that hashref are as follows:

event

    { event => 'results_event', }

Mandatory. Specifies the name of the event to emit when results are ready. See OUTPUT section for more information.

uri

    { uri => 'http://uri_to_paste_you_want_to_retrieve.com' }

Mandatory. Takes a scalar containing a URI poiting to the paste you would like to retrieve. See "SUPPORTED PASTEBINS" section in documentation for WWW::Pastebin::Many::Retrieve module regarding accepted pastebins.

session

    { session => 'other' }

    { session => $other_session_reference }

    { session => $other_session_ID }

Optional. Takes either an alias, reference or an ID of an alternative session to send output to.

user defined

    {
        _user    => 'random',
        _another => 'more',
    }

Optional. Any keys starting with _ (underscore) will not affect the component and will be passed back in the result intact.

shutdown

    $poe_kernel->post( paster => 'shutdown' );

Takes no arguments. Tells the component to shut itself down.

OUTPUT

    $VAR1 = {
        'response' => {
            'hits' => '0',
            'lang' => 'plaintext',
            'name' => 'N/A',
            'content' => 'paste content here',
            'age' => '14.03.08 21:59'
        },
        'content' => 'paste content here',
        'uri' => 'http://phpfi.com/302683',
        '_random' => 'Sun Mar 30 07:33:00 2008'
    };

The event handler set up to handle the event which you've specified in the event argument to retrieve() method/event will recieve input in the $_[ARG0] in a form of a hashref. The possible keys/value of that hashref are as follows:

content

    { 'content' => 'paste content here', }

Unless an error occured the content key will be present and its value will be the actual content of the paste you retrieved.

response

    {
        'response' => {
            'hits' => '0',
            'lang' => 'plaintext',
            'name' => 'N/A',
            'content' => 'paste content here',
            'age' => '14.03.08 21:59'
        },
    }

Unless an error occured the response key will contain the return value of response() method of the specific object which was used to retrieve your paste. See WWW::Pastebin::Many::Retrieve for more information.

error

    { 'error' => 'Nework error: 500 read timeout' }

If an error occured during retrieval of your paste the error key will be present and its value will be a human parsable error message explaining why we failed.

uri

    { 'uri' => 'http://phpfi.com/302683', }

The uri key will contain whatever you've specified in the uri argument to retrieve() event/method.

user defined

    { '_blah' => 'foos' }

Any arguments beginning with _ (underscore) passed into the retrieve() event/method will be present intact in the result.

SEE ALSO

POE, WWW::Pastebin::Many::Retrieve

AUTHOR

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

BUGS

Please report any bugs or feature requests to bug-poe-component-www-pastebin-many-retrieve at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-WWW-Pastebin-Many-Retrieve. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc POE::Component::WWW::Pastebin::Many::Retrieve

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2008 Zoffix Znet, all rights reserved.

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