#!/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();