summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-09-02 10:50:19 -0400
committerJesse Luehrs <doy@tozt.net>2013-09-02 10:53:59 -0400
commit61fa7917ab15e46892211f712e554eaccf8857fb (patch)
tree11a089d2b76a45708bed85d4b17ab0a72761410f
parent39d3a137834aa90350e1947b734e003986bd5d78 (diff)
downloadweb-request-61fa7917ab15e46892211f712e554eaccf8857fb.tar.gz
web-request-61fa7917ab15e46892211f712e554eaccf8857fb.zip
add Web::Response->to_app (backported from Plack e3d0dde)
-rw-r--r--lib/Web/Response.pm10
-rw-r--r--t/response-to_app.t21
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/Web/Response.pm b/lib/Web/Response.pm
index ae22bc0..f9d0bb5 100644
--- a/lib/Web/Response.pm
+++ b/lib/Web/Response.pm
@@ -158,6 +158,11 @@ sub finalize {
});
}
+sub to_app {
+ my $self = shift;
+ return sub { $self->finalize };
+}
+
sub _finalize_streaming {
my $self = shift;
@@ -360,6 +365,11 @@ Returns a valid L<PSGI> response, based on the values given. This can be either
an arrayref or a coderef, depending on if an immediate or streaming response
was provided. If both were provided, the streaming response will be preferred.
+=method to_app
+
+Returns a PSGI application which just returns the response in this object
+directly.
+
=cut
1;
diff --git a/t/response-to_app.t b/t/response-to_app.t
new file mode 100644
index 0000000..703953d
--- /dev/null
+++ b/t/response-to_app.t
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Plack::Test;
+
+use HTTP::Request::Common;
+use Web::Response;
+
+my $res = Web::Response->new(status => 200);
+$res->content("hello");
+
+test_psgi $res->to_app, sub {
+ my $cb = shift;
+
+ my $res = $cb->(GET "/");
+ is $res->code, 200, 'response code';
+ is $res->content, 'hello', 'content';
+};
+
+done_testing;