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 return responses as Future objects:
28 sub response_is_future { 1 }
31 my ($self, $method, $url, $args) = @_;
35 my $future = Future->new;
37 # Again, this example glosses over transforming the request and response
38 # to and from the actual user agent, but such details are the whole
41 $ua->nonblocking_callback(sub {
44 if ($resp->{success}) {
57 This module provides an interface for an L<HTTP::AnyUA> "backend," which is an adapter that adds
58 support for using a type of user agent with L<HTTP::AnyUA>.
60 This class should not be instantiated directly, but it may be convenient for backend implementations
63 At its core, a backend simply takes a set of standard arguments that represent an HTTP request,
64 transforms that request into a form understood by an underlying user agent, calls upon the user
65 agent to make the request and get a response, and then transforms that response into a standard
66 form. The standard forms for the request and response are based on L<HTTP::Tiny>'s arguments and
67 return value to and from its L<request|HTTP::Tiny/request> method.
72 * L<HTTP::AnyUA/REQUEST> - Explanation of the request arguments
73 * L<HTTP::AnyUA/RESPONSE> - Explanation of the response
80 our $VERSION = '9999.999'; # VERSION
85 $backend = HTTP
::AnyUA
::Backend
::MyUserAgent-
>new($my_user_agent);
87 Construct a new backend
.
93 my $ua = shift or die 'User agent is required';
94 bless {ua
=> $ua}, $class;
99 $response = $backend->request($method => $url, \
%options);
101 Make a request
, get a response
.
103 This must be overridden by implementations
.
108 die 'Not yet implemented';
113 Get the user agent that was passed to L
</new
>.
117 sub ua
{ shift-
>{ua
} }
119 =attr response_is_future
121 Get whether
or not responses are L
<Future
> objects
. Default
is false
.
123 This may be overridden by implementations
.
127 sub response_is_future
{ 0 }