The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Chain - A web request chain

VERSION

version 0.100

SYNOPSIS

# Coderef usage

use WWW::Chain; # exports www_chain

my $chain = www_chain(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';

  has path_part => (
    is => 'ro',
    required => 1,
  );

  # Function used to determine first requests on class, will be added to BUILDARGS
  sub start_chain {
    return HTTP::Request->new( GET => 'https://conflict.industries/'.$_[0]->path_part ), 'first_response';
  }

  sub first_response {
    $_[0]->stash->{a} = 1;
    return HTTP::Request->new( GET => 'https://conflict.industries/'.$_[0]->path_part ), 'second_response';
  }

  sub second_response {
    $_[0]->stash->{b} = 2;
    return;
  }
}

my $chain = TestWWWChainMethods->new( path_part => 'wwwchain' );

# 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

More documentation to come, API stabilized.

SUPPORT

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/Getty/p5-www-chain

git clone https://github.com/Getty/p5-www-chain.git

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudss.us/

COPYRIGHT AND LICENSE

This software is copyright (c) 2024 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.