1 package HTTP
::AnyUA
::Backend
;
2 # ABSTRACT: A base class for HTTP::AnyUA backends
6 package HTTP::AnyUA::Backend::MyUserAgent;
8 use parent 'HTTP::AnyUA::Backend';
10 sub response_is_future { 0 }
13 my ($self, $method, $url, $args) = @_;
17 # Here is where you transform the arguments into a request that $ua
18 # understands, make the request against $ua and get a response, and
19 # transform the response to the expected hashref form.
21 my $resp = $ua->make_request();
26 ### Non-blocking user agents are expected to return Future objects:
30 sub response_is_future { 1 }
33 my ($self, $method, $url, $args) = @_;
37 my $future = Future->new;
39 # Again, this example glosses over transforming the request and response
40 # to and from the actual user agent, but such details are the whole
43 $ua->nonblocking_callback(sub {
46 if ($resp->{success}) {
59 This module provides an interface for an L<HTTP::AnyUA> "backend," which is an adapter that adds
60 support for using a type of user agent with L<HTTP::AnyUA>.
62 This class should not be instantiated directly, but it may be convenient for backend implementations
65 At its core, a backend simply takes a set of standard arguments that represent an HTTP request,
66 transforms that request into a form understood by an underlying user agent, calls upon the user
67 agent to make the request and get a response, and then transforms that response into a standard
68 form. The standard forms for the request and response are based on L<HTTP::Tiny>'s arguments and
69 return value to and from its L<request|HTTP::Tiny/request> method.
74 * L<HTTP::AnyUA/The Request> - Explanation of the request arguments
75 * L<HTTP::AnyUA/The Response> - Explanation of the response
82 our $VERSION = '9999.999'; # VERSION
87 $backend = HTTP
::AnyUA
::Backend
::MyUserAgent-
>new($my_user_agent);
89 Construct a new backend
.
95 my $ua = shift or die 'User agent is required';
96 bless {ua
=> $ua}, $class;
101 $response = $backend->request($method => $url, \
%options);
103 Make a request
, get a response
.
105 This must be overridden by implementations
.
110 die 'Not yet implemented';
115 Get the user agent that was passed to L
</new
>.
119 sub ua
{ shift-
>{ua
} }
121 =attr response_is_future
123 Get whether
or not responses are L
<Future
> objects
. Default
is false
.
125 This may be overridden by implementations
.
129 sub response_is_future
{ 0 }