X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-HTTP-AnyUA;a=blobdiff_plain;f=lib%2FHTTP%2FAnyUA%2FBackend%2FMojo%2FUserAgent.pm;h=aeb2b1f5838c3362d9517eec9a68557b860c0d9c;hp=003d10f1132c6a9711d71e606baa391d01248f3f;hb=8306d573a50cbac0d76bf01ce98e82beec36e42d;hpb=b671717fae8b8c6b3f22355f4c16b5cbe0a8ffd0 diff --git a/lib/HTTP/AnyUA/Backend/Mojo/UserAgent.pm b/lib/HTTP/AnyUA/Backend/Mojo/UserAgent.pm index 003d10f..aeb2b1f 100644 --- a/lib/HTTP/AnyUA/Backend/Mojo/UserAgent.pm +++ b/lib/HTTP/AnyUA/Backend/Mojo/UserAgent.pm @@ -6,6 +6,9 @@ package HTTP::AnyUA::Backend::Mojo::UserAgent; This module adds support for the HTTP client L to be used with the unified programming interface provided by L. +If installed, requests will return L rather than L. This allows the use of the +C<< ->get >> method to await a result. + =head1 CAVEATS =for :list @@ -29,13 +32,21 @@ use Future; use Scalar::Util; +my $future_class; +BEGIN { + $future_class = 'Future'; + eval 'use Future::Mojo'; ## no critic + $future_class = 'Future::Mojo' if !$@; +} + + sub response_is_future { 1 } sub request { my $self = shift; my ($method, $url, $args) = @_; - my $future = Future->new; + my $future = $future_class->new; my $tx = $self->_munge_request(@_); @@ -142,7 +153,7 @@ sub _munge_response { } my $err = $tx->error; - if ($err and !$err->{code}) { + if ($err && !$err->{code}) { return HTTP::AnyUA::Util::internal_exception($err->{message}, $resp); }