-This software is copyright (c) 2017 by Charles McGarvey.
+This software is copyright (c) 2019 by Charles McGarvey.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
--- The GNU General Public License, Version 1, February 1989 ---
-This software is Copyright (c) 2017 by Charles McGarvey.
+This software is Copyright (c) 2019 by Charles McGarvey.
This is free software, licensed under:
--- The Artistic License 1.0 ---
-This software is Copyright (c) 2017 by Charles McGarvey.
+This software is Copyright (c) 2019 by Charles McGarvey.
This is free software, licensed under:
name = HTTP-AnyUA
author = Charles McGarvey <chazmcgarvey@brokenzipper.com>
copyright_holder = Charles McGarvey
-copyright_year = 2017
+copyright_year = 2019
license = Perl_5
[@Author::CCM]
-AutoPrereqs.skip[0] = ^(AnyEvent::.+|HTTP::Request|Net::Curl::Easy)$
+AutoPrereqs.skip[0] = ^(AnyEvent::.+|Future::Mojo|HTTP::Request|Net::Curl::Easy)$
AutoPrereqs.skip[1] = ^(JSON|AnyEvent|Plack::.+|Mojo::.+)$
-[Prereqs / RuntimeSuggests]
+[Prereqs / RuntimeRecommends]
HTTP::Tiny = 0
[Prereqs / TestSuggests]
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
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);
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 module adds support for the HTTP client L<Mojo::UserAgent> to be used with the unified
programming interface provided by L<HTTP::AnyUA>.
+If installed, requests will return L<Future::Mojo> rather than L<Future>. This allows the use of the
+C<< ->get >> method to await a result.
+
=head1 CAVEATS
=for :list
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(@_);
--- /dev/null
+#!perl
+
+use warnings;
+use strict;
+
+use lib 't/lib';
+
+use HTTP::AnyUA;
+use Test::More tests => 2;
+use Util qw(test_user_agent);
+
+HTTP::AnyUA->register_backend(Mock => '+MockBackend');
+
+subtest 'test Future::Mojo as a Future response' => sub {
+ test_user_agent 'Mojo::UserAgent' => sub {
+ plan tests => 1;
+
+ my $ua = shift;
+ my $any_ua = HTTP::AnyUA->new($ua, response_is_future => 1);
+
+ my $url = 'http://acme.tld/';
+
+ my $future = $any_ua->get($url);
+ isa_ok($future, 'Future::Mojo');
+
+ return $future;
+ };
+};
+
+subtest 'test AnyEvent::Future as a Future response' => sub {
+ test_user_agent 'AnyEvent::HTTP' => sub {
+ plan tests => 1;
+
+ my $ua = shift;
+ my $any_ua = HTTP::AnyUA->new($ua, response_is_future => 1);
+
+ my $url = 'http://acme.tld/';
+
+ my $future = $any_ua->get($url);
+ isa_ok($future, 'AnyEvent::Future');
+
+ return $future;
+ };
+};
+
--- /dev/null
+package AnyEvent::Future;
+
+use warnings;
+use strict;
+
+use parent 'Future';
+
+1;
--- /dev/null
+package Future::Mojo;
+
+use warnings;
+use strict;
+
+use parent 'Future';
+
+1;