diff options
-rw-r--r-- | lib/Web/Response.pm | 10 | ||||
-rw-r--r-- | t/response-to_app.t | 21 |
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; |