Skip to content

Commit

Permalink
Merge pull request #479 from oalders/master
Browse files Browse the repository at this point in the history
Make return of response_cb explicit rather than implicit.
  • Loading branch information
miyagawa committed Nov 26, 2014
2 parents 86ec1d5 + 8b26f3e commit e82b801
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/Plack/Middleware.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ is pointless, so you're recommended to use the C<response_cb> wrapper
function in L<Plack::Util> when implementing a post processing
middleware.
my $res = $app->($env);
Plack::Util::response_cb($res, sub {
my $res = shift;
# do something with $res;
});
sub call {
my($self, $env) = @_;
# pre-processing $env
my $res = $app->($env);
return Plack::Util::response_cb($res, sub {
my $res = shift;
# do something with $res;
});
}
The callback function gets a response as an array reference, and you can
update the reference to implement the post-processing. In the normal
Expand All @@ -119,7 +124,7 @@ described below.
sub call {
my($self, $env) = @_;
my $res = $self->app->($env);
Plack::Util::response_cb($res, sub {
return Plack::Util::response_cb($res, sub {
my $res = shift;
$res->[0] = 500;
return;
Expand Down

0 comments on commit e82b801

Please sign in to comment.