Skip to content

Commit

Permalink
Merge e3d0dde into 0cda5b6
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge committed Jun 12, 2013
2 parents 0cda5b6 + e3d0dde commit 984c0df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Go to http://github.com/plack/Plack/issues for the roadmap and known issues.

{{$NEXT}}
[IMPROVEMENTS]
- $res->to_app shortcut (ether)

1.0024 2013-05-01 10:05:56 PDT
[IMPROVEMENTS]
Expand Down
13 changes: 13 additions & 0 deletions lib/Plack/Response.pm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ sub finalize {
];
}

sub to_app {
my $self = shift;
return sub { $self->finalize };
}


sub _body {
my $self = shift;
my $body = $self->body;
Expand Down Expand Up @@ -296,6 +302,13 @@ B<does not> convert string formats such as C<+3M>.
Returns the status code, headers, and body of this response as a PSGI
response array reference.
=item to_app
$app = $res->to_app;
A helper shortcut for C<< sub { $res->finalize } >>.
=back
=head1 AUTHOR
Expand Down
31 changes: 31 additions & 0 deletions t/Plack-Response/to_app.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use strict;
use warnings;
use Test::More;
use HTTP::Request::Common;
use Plack::Test;
use Plack::Response;

sub res {
my $res = Plack::Response->new;
my %v = @_;
while (my($k, $v) = each %v) {
$res->$k($v);
}
$res;
}

my $res = res(
status => 200,
body => '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;

0 comments on commit 984c0df

Please sign in to comment.