From 61fa7917ab15e46892211f712e554eaccf8857fb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 2 Sep 2013 10:50:19 -0400 Subject: add Web::Response->to_app (backported from Plack e3d0dde) --- lib/Web/Response.pm | 10 ++++++++++ t/response-to_app.t | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 t/response-to_app.t 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 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; -- cgit v1.2.3-54-g00ecf