]> Dogcows Code - chaz/p5-HTTP-AnyUA/commitdiff
respond with Future subclasses
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 17 Mar 2019 06:42:02 +0000 (00:42 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 17 Mar 2019 06:42:02 +0000 (00:42 -0600)
LICENSE
dist.ini
lib/HTTP/AnyUA/Backend/AnyEvent/HTTP.pm
lib/HTTP/AnyUA/Backend/Mojo/UserAgent.pm
t/50-future-subclass.t [new file with mode: 0644]
t/lib/AnyEvent/Future.pm [new file with mode: 0644]
t/lib/Future/Mojo.pm [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
index a2abd4e5f6c828f4b318cdbed0ad4ef46cf00746..2eb2acb039dee44387225f9ebcec91134ea71711 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-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.
@@ -12,7 +12,7 @@ b) the "Artistic License"
 
 --- 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:
 
@@ -272,7 +272,7 @@ That's all there is to it!
 
 --- 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:
 
index d554bf6d281a9edf6641c330d6319bda72c5ef64..d8d6a4e7742bff1ec22bf8c445c5540bbd9b60a2 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -2,14 +2,14 @@
 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]
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 {
index 436eddf4ee61dc63d19146c946599c233a67248e..aeb2b1f5838c3362d9517eec9a68557b860c0d9c 100644 (file)
@@ -6,6 +6,9 @@ package HTTP::AnyUA::Backend::Mojo::UserAgent;
 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
@@ -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(@_);
 
diff --git a/t/50-future-subclass.t b/t/50-future-subclass.t
new file mode 100644 (file)
index 0000000..619d713
--- /dev/null
@@ -0,0 +1,45 @@
+#!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;
+    };
+};
+
diff --git a/t/lib/AnyEvent/Future.pm b/t/lib/AnyEvent/Future.pm
new file mode 100644 (file)
index 0000000..32750e2
--- /dev/null
@@ -0,0 +1,8 @@
+package AnyEvent::Future;
+
+use warnings;
+use strict;
+
+use parent 'Future';
+
+1;
diff --git a/t/lib/Future/Mojo.pm b/t/lib/Future/Mojo.pm
new file mode 100644 (file)
index 0000000..44b8745
--- /dev/null
@@ -0,0 +1,8 @@
+package Future::Mojo;
+
+use warnings;
+use strict;
+
+use parent 'Future';
+
+1;
This page took 0.032363 seconds and 4 git commands to generate.