]> Dogcows Code - chaz/p5-HTTP-AnyUA/blobdiff - lib/HTTP/AnyUA/Backend/AnyEvent/HTTP.pm
respond with Future subclasses
[chaz/p5-HTTP-AnyUA] / lib / HTTP / AnyUA / Backend / AnyEvent / HTTP.pm
index 14f3b288e3e96cd11dca95e8a915ac78d14f510d..334a664310c89de98659adfc9cc090bad8193035 100644 (file)
@@ -6,6 +6,9 @@ package HTTP::AnyUA::Backend::AnyEvent::HTTP;
 This module adds support for the HTTP client L<AnyEvent::HTTP> to be used with the unified
 programming interface provided by L<HTTP::AnyUA>.
 
+If installed, requests will return L<AnyEvent::Future> rather than L<Future>. This allows the use of
+the C<< ->get >> method to await a result.
+
 =head1 SEE ALSO
 
 =for :list
@@ -24,6 +27,14 @@ use Future;
 use HTTP::AnyUA::Util;
 
 
+my $future_class;
+BEGIN {
+    $future_class = 'Future';
+    eval 'use AnyEvent::Future';    ## no critic
+    $future_class = 'AnyEvent::Future' if !$@;
+}
+
+
 =method options
 
     $backend->options(\%options);
@@ -41,7 +52,7 @@ sub request {
     my ($method, $url, $args) = @_;
 
     my %opts    = $self->_munge_request($method, $url, $args);
-    my $future  = Future->new;
+    my $future  = $future_class->new;
 
     require AnyEvent::HTTP;
     AnyEvent::HTTP::http_request($method => $url, %opts, sub {
This page took 0.018992 seconds and 4 git commands to generate.