Created
September 30, 2009 21:39
-
-
Save miyagawa/198482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Plack::Middleware::RequestResponseWrapper; | |
use strict; | |
use warnings; | |
use base qw( Plack::Middleware ); | |
use Plack::Request; | |
use Plack::Response; | |
sub call { | |
my $self = shift; | |
my $req = Plack::Request->new(shift); | |
my $res = $self->app->($req); | |
return $res->finalize; | |
} | |
1; | |
__END__ | |
=head1 NAME | |
Plack::Middleware::RequestResponseWrapper - Wraps your app with Plack::Request and Plack::Response | |
=head1 SYNOPSIS | |
# in app.psgi | |
use Plack::Builder; | |
use Plack::Middleware qw(RequestResponseWrapper); | |
my $app = sub { | |
my($req, $res) = @_; | |
$res->code(200); | |
$res->header('Content-Type' => 'text/plain'); | |
$res->body('Hello World'); | |
}; | |
builder { | |
enable Plack::Middleware::RequestResponseWrapper; | |
$app; | |
}; | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment