NAME

POE::Component::WWW::GetPageTitle - non-blocking wrapper around WWW::GetPageTitle

SYNOPSIS

use strict;
use warnings;

use POE qw(Component::WWW::GetPageTitle);

my $poco = POE::Component::WWW::GetPageTitle->spawn;

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

$poe_kernel->run;

sub _start {
    $poco->get_title( {
            page  => 'http://zoffix.com/',
            event => 'result',
        }
    );
}

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

    if ( $in_ref->{error} ) {
        print "ERROR: $in_ref->{error}\n";
    }
    else {
        print "Title of $in_ref->{page} is $in_ref->{title}\n";
    }

    $poco->shutdown;
}

Using event based interface is also possible of course.

DESCRIPTION

The module is a non-blocking wrapper around WWW::GetPageTitle which provides interface to fetch page titles.

CONSTRUCTOR

spawn

my $poco = POE::Component::WWW::GetPageTitle->spawn;

POE::Component::WWW::GetPageTitle->spawn(
    alias => 'page_title',
    ua => LWP::UserAgent->new,
    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::GetPageTitle object. It takes a few arguments, all of which are optional. The possible arguments are as follows:

alias

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

Optional. Specifies a POE Kernel alias for the component.

ua

->spawn( ua => LWP::UserAgent->new );

Optional. The ua argument is passed directly to WWW::GetPageTitle's constructor. See documentation for WWW::GetPageTitle for more details.

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

get_title

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

Takes a hashref as an argument, does not return a sensible return value. See get_title 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

get_title

$poe_kernel->post( page_title => get_title => {
        event       => 'event_for_output',
        page        => 'http://zoffix.com/',
        _blah       => 'pooh!',
        session     => 'other',
    }
);

Instructs the component to fetch the title of the page. 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.

page

{ page => 'http://zoffix.com/' },

Mandatory. Specifies the URI of the page of which to get the title.

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( page_title => 'shutdown' );

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

OUTPUT

$VAR1 = {
    'page' => 'http://google.ca',
    'title' => 'Google',
    '_blah' => 'foos'
};

$VAR1 = {
    'page'  => 'http://google.ca',
    'error' => 'Network error: 500 timeout',
    '_blah' => 'foos'
};

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

page

{ 'page' => 'http://google.ca', }

The page key will contain the URI of the page that was accessed.

title

{ 'title' => 'Google', }

The title key (providing no errors occurred) will contain the title of the page that was accessed.

error

{ 'error' => 'Network error: 500 timeout', }

If a network error occurred, the error key will be present and will contain the description of the error.

user defined

{ '_blah' => 'foos' }

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

SEE ALSO

POE, WWW::GetPageTitle

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.