GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
POE(3) User Contributed Perl Documentation POE(3)

LWP::UserAgent::POE - Drop-in LWP::UserAgent replacement in POE environments

    use LWP::UserAgent::POE;

    my $ua = LWP::UserAgent::POE->new();

      # The following command looks (and behaves) like it's blocking, 
      # but it actually keeps the POE kernel ticking and processing 
      # other tasks. post() and request() work as well.
    my $resp = $ua->get( "http://www.yahoo.com" );

    if($resp->is_success()) {
        print $resp->content();
    } else {
        print "Error: ", $resp->message(), "\n";
    }

    POE::Kernel->run();

LWP::UserAgent::POE is a subclass of LWP::UserAgent and works well in a POE environment. It is a drop-in replacement for LWP::UserAgent in systems that are already using LWP::UserAgent synchronously and want to play nicely with POE.

The problem: LWP::UserAgent by itself is synchronous and blocks on requests until the response from the network trickles in. This is unacceptable in POE, as the POE kernel needs to continue processing other tasks until the HTTP response arrives.

LWP::UserAgent::POE to the rescue. Its request() method and all related methods like get(), post() etc. work just like in the original. But if you peek under the hood, they're sending a request to a running POE::Component::Client::HTTP component and return a valid $response object when a response from the network is available. Although the program flow seems to be blocked, it's not. LWP::UserAgent::POE works the magic behind the scenes to keep the POE kernel ticking and process other tasks.

The net effect is that you can use LWP::UserAgent::POE just like LWP::UserAgent in a seemingly synchronous way.

Note that this module is not a POE component. Instead, it is a subclass of LWP::UserAgent. It is self-contained, it even spawns the POE::Component::Client::HTTP component in its constructor unless there's one already running that has been started by another instance.

Just like LWP::UserAgent, LWP::UserAgent::POE supports cookies if you define a cookie jar:

   my $ua = LWP::UserAgent::POE->new(
       cookie_jar => HTTP::Cookies->new(),
   );

Just make sure to pass these parameters to the constructor, see the 'Bugs' section below on what hasn't been implemented yet.

Currently, you can't call LWP::UserAgent's parameter methods, like

    $ua->timeout();

as this won't be propagated to the POE component running the HTTP requests. It might be added later. Currently, you have to add it to the constructor, like

    my $ua = LWP::UserAgent->new( timeout => 10 );

to take effect. LWP::UserAgent::POE translates the LWP::UserAgent parameter names to POE::Component::Client::HTTP's parameters, which are slightly different.

Copyright 2008 by Mike Schilli and Rocco Caputo, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

The code of this module is based on Rocco Caputo's "pua-defer" code, which has been included with his permission.

2008, Mike Schilli <cpan@perlmeister.com>

2014-05-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.