tomhukins has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use the POE::Component::Client::HTTP module to create some Web client code that can download multiple pages simultaneously.

I'm aware of LWP::Parallel::UserAgent, but I'd like to get to grips with POE, and now seemed like as good a time as any. There isn't much example POE code available yet, although POE's Web site contains some helpful material.

The problem I'm encountering is that I can allocate a set of URLs for a given POE session, but I can't create one pool of URLs which sessions work through together until all URLs have been queried.

Here's some code that spawns 3 sessions, each of which retrieve a page:

#!/usr/bin/perl -Tw use strict; use HTTP::Request::Common qw(GET); use POE qw(Component::Client::HTTP); use vars qw(@url); # Create a POE HTTP client component POE::Component::Client::HTTP->spawn( 'Timeout' => 20 ); # Create sessions to be used for HTTP requests for (1..3) { POE::Session->create( inline_states => { _start => \&client_start, got_response => \&client_got_response } ); } $poe__kernel->run(); sub client_start { my ($kernel, $heap) = @_[KERNEL, HEAP]; $kernel->post( 'weeble', 'request', got_response => GET 'http://URL_HERE/' ); warn 'STARTED'; } sub client_got_response { my($heap, $request_packet, $response_packet) = @_[HEAP, ARG0, ARG1 +]; my $http_request = $request_packet->[0]; my $http_response = $response_packet->[0]; print "REQUEST\n",$http_request->headers_as_string(); print "RESPONSE\n",$http_response->headers_as_string(); }

To use a pool of URLs, I've removed the $kernel->post call in my client_start subroutine, and placed the following before $poe_kernel->run():

foreach my $url (@url) { $poe_kernel->post( 'weeble', 'request', got_response => GET $url ); }

This fails with the error Can't locate object method "postback" via package "POE::Kernel" at /usr/local/lib/perl5/site_perl/5.005/POE/Component/Client/HTTP.pm line 208. Can anyone help me solve this, maybe using another technique?