Let me just say a few sentences: PSGI specifies - like CGI - a standard interface between web servers and Perl web applications (or web frameworks). And Plack is a toolkit for PSGI. With plackup you can start PSGI apps from the command line.
Save this short script as app.psgi and run plackup in the shell:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my $app = sub { my $env = shift; return [ 200, ['Content-Type' => 'text/html'], ['<html><body><pre>'.Dumper($env).'</pre></body></html>'], ]; };Now, point your browser to http://localhost:5000/ and you will see the PSGI environment variables.
With plackup -r you get a restarting server (very useful during development). And -e allows you to wrap middlewares around your web app:
plackup -e 'enable "Debug"' app.psgi
will give you a nice debug panel. (You have to install Plack::Middleware::Debug.)Normally you do not use Plack directly, your web application framework does it. But for really small web apps, I use Plack::Request and Plack::Response (together with Template Toolkit) directly.
Links:
Can -r be used in production, or would there be a performance hit?
ReplyDeleteThe problem is not -r, it is the standalone server of plackup: It serves just a single request at a time!
ReplyDeleteWe use something similar in production. But it is not checked on every request. A separate process does it.