You might want to check out POE::Component::Client::UserAgent. One of the test scripts (t/02-multi.t) does pretty much what you want.

Update 11/03/02: Here is a much shorter script, that at least demonstrates fetching a list of documents, and uses 10 threads. Liberal adding of "print" statements to assist understanding of the code is left as an exercise for the reader.

#!/usr/bin/perl -w use strict; use POE; use POE::Component::Client::UserAgent; my @urls = map { "http://sam.vilain.net/$_" } qw(index.html hobbies.html CV foo bar); sub _start { $_[HEAP]->{alias} = "useragent".$_[ARG0]; POE::Component::Client::UserAgent->new (alias => $_[HEAP]->{alias}); $_[KERNEL]->yield("next"); } sub next { if (my $url = pop @urls) { $_[KERNEL]->post ( $_[HEAP]->{alias} => "request", { request => HTTP::Request->new(GET => $url), response => $_[SESSION]->postback('next') } ); } else { $_[KERNEL]->post ( $_[HEAP]->{alias} => "shutdown", ); } } for (1..10) { POE::Session -> create ( inline_states => { _start => \&_start, next => \&next, }, args => [ $_ ], # arguments ); } $poe_kernel->run();
PS LWP::Parallel::UserAgent 2.51 has a bug;
  1. The line 182 of LWP::Parallel::UserAgent.pm needs to be my $self = new LWP::UserAgent; instead of my $self = new LWP::UserAgent $init;
  2. You may also need to insert the line use HTML::HeadParser; anywhere near the top of LWP::Parallel::Protocol.pm.

In reply to use POE; by mugwumpjism
in thread Using LWP::Parallel by wilstephens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.