]>
Dogcows Code - chaz/p5-HTTP-AnyUA/blob - lib/HTTP/AnyUA/Backend.pm
1 package HTTP
::AnyUA
::Backend
;
2 # ABSTRACT: A base class for HTTP::AnyUA backends
8 our $VERSION = '0.900'; # VERSION
14 my $ua = shift or die 'User agent is required';
15 bless {ua
=> $ua}, $class;
20 die 'Not yet implemented';
24 sub ua
{ shift-
>{ua
} }
27 sub response_is_future
{ 0 }
39 HTTP::AnyUA::Backend - A base class for HTTP::AnyUA backends
47 package HTTP::AnyUA::Backend::MyUserAgent;
49 use parent 'HTTP::AnyUA::Backend';
51 sub response_is_future { 0 }
54 my ($self, $method, $url, $args) = @_;
58 # Here is where you transform the arguments into a request that $ua
59 # understands, make the request against $ua and get a response, and
60 # transform the response to the expected hashref form.
62 my $resp = $ua->make_request();
67 ### Non-blocking user agents return responses as Future objects:
69 sub response_is_future { 1 }
72 my ($self, $method, $url, $args) = @_;
76 my $future = Future->new;
78 # Again, this example glosses over transforming the request and response
79 # to and from the actual user agent, but such details are the whole
82 $ua->nonblocking_callback(sub {
85 if ($resp->{success}) {
98 This module provides an interface for an L<HTTP::AnyUA> "backend," which is an adapter that adds
99 support for using a type of user agent with L<HTTP::AnyUA>.
101 This class should not be instantiated directly, but it may be convenient for backend implementations
104 At its core, a backend simply takes a set of standard arguments that represent an HTTP request,
105 transforms that request into a form understood by an underlying user agent, calls upon the user
106 agent to make the request and get a response, and then transforms that response into a standard
107 form. The standard forms for the request and response are based on L<HTTP::Tiny>'s arguments and
108 return value to and from its L<request|HTTP::Tiny/request> method.
114 Get the user agent that was passed to L</new>.
116 =head2 response_is_future
118 Get whether or not responses are L<Future> objects. Default is false.
120 This may be overridden by implementations.
126 $backend = HTTP::AnyUA::Backend::MyUserAgent->new($my_user_agent);
128 Construct a new backend.
132 $response = $backend->request($method => $url, \%options);
134 Make a request, get a response.
136 This must be overridden by implementations.
144 L<HTTP::AnyUA/REQUEST> - Explanation of the request arguments
148 L<HTTP::AnyUA/RESPONSE> - Explanation of the response
154 Please report any bugs or feature requests on the bugtracker website
155 L<https://github.com/chazmcgarvey/HTTP-AnyUA/issues>
157 When submitting a bug or request, please include a test-file or a
158 patch to an existing test-file that illustrates the bug or desired
163 Charles McGarvey <chazmcgarvey@brokenzipper.com>
165 =head1 COPYRIGHT AND LICENSE
167 This software is copyright (c) 2017 by Charles McGarvey.
169 This is free software; you can redistribute it and/or modify it under
170 the same terms as the Perl 5 programming language system itself.
This page took 0.036291 seconds and 4 git commands to generate.