NAME
WWW::Chain - A web request chain
VERSION
version 0.002
SYNOPSIS
# Coderef usage
my $chain = WWW::Chain->new(HTTP::Request->new( GET => 'http://localhost/' ), sub {
my ( $chain, $response ) = @_;
$chain->stash->{first_request} = 'done';
return
HTTP::Request->new( GET => 'http://localhost/' ),
HTTP::Request->new( GET => 'http://other.localhost/' ),
sub {
my ( $chain, $first_response, $second_response ) = @_;
$chain->stash->{two_calls_finished} = 'done';
return;
};
});
# Method usage (can be mixed with Coderef)
{
package TestWWWChainMethods;
use Moo;
extends 'WWW::Chain';
sub first_request {
$_[0]->stash->{a} = 1;
return HTTP::Request->new( GET => 'http://duckduckgo.com/' ), "second_request";
}
sub second_request {
$_[0]->stash->{b} = 2;
return;
}
}
my $chain = TestWWWChainMethods->new(HTTP::Request->new( GET => 'http://duckduckgo.com/' ), 'first_request');
# Blocking usage:
my $ua = WWW::Chain::UA::LWP->new;
$ua->request_chain($chain);
# ... or non blocking usage example:
my @http_requests = @{$chain->next_requests};
# ... do something with the HTTP::Request objects to get HTTP::Response objects
$chain->next_responses(@http_responses);
# repeat those till $chain->done
# Working with the result
print $chain->stash->{two_calls_finished};
DESCRIPTION
The implementation is not finished (but fully working), API changes may occur...
AUTHOR
Torsten Raudssus <torsten@raudss.us>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Torsten Raudssus.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.