Created
July 12, 2011 08:55
-
-
Save yko/1077653 to your computer and use it in GitHub Desktop.
PSGI Hello World with Plack Debug middleware
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Plack::Builder; | |
my $body = join '', <DATA>; | |
my $app = sub { | |
my $self = shift; | |
# Do whatever you want, but return PSGI-compatible response | |
# see http://search.cpan.org/~miyagawa/PSGI/PSGI.pod | |
[200, ['Content-Type' => 'text/html'], [ $body ]]; | |
}; | |
builder { | |
# Precious debug info. Right on your page! | |
enable 'Debug'; | |
# Make Plack middleware render some static for you | |
enable "Static", | |
path => qr{\.(?:js|css|jpe?g|gif|ico|png|html?|swf|txt)$}, | |
root => './htdocs'; | |
# Let Plack care about length header | |
enable "ContentLength"; | |
$app; | |
} | |
__DATA__ | |
<!doctype html> | |
<html> | |
<head> | |
<title>Few words about Plack and PSGI</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment