in reply to Re^2: How do I run a loop within a PSGI application
in thread How do I run a loop within a PSGI application
"...I have been wondering about the possibility of using PSGI/Plack without using any framework"
Me too. My 2 ¢:
# myapp.psgi use Plack::Request; use Plack::App::URLMap; use HTML::HTML5::Builder qw[:standard]; my $slash = sub { my $env = shift; my $status = 200; my $request = Plack::Request->new($env); my $headers = [ 'Content-Type' => 'text/plain', 'Content-Length' => length $request->param('nose') ]; my $body = [ $request->param('nose') ]; [ $status, $headers, $body ]; }; my $tiny_monk = sub { my @things = ( "Sex", "Drugs", "Rock and Roll", "Charlie Haden", ) +; my $html = html( -lang => 'en', head( title('My Favorite Things'), Meta( -charset => 'utf-8' ) +, ), body( h1('Testomato'), p('My Favorite Things...'), ul( map li($_), @things ), ), ); my $status = 200; my $headers = [ 'Content-Type' => 'text/html', 'Content-Length' => length $html ]; my $body = [ $html ]; [ $status, $headers, $body ]; }; my $urlmap = Plack::App::URLMap->new; $urlmap->mount( "/" => $slash ); $urlmap->mount( "/tiny_monk" => $tiny_monk ); my $app = $urlmap->to_app; __END__
Start the app with plackup myapp.psgi and try curl http://localhost:5000/?nose=cuke as well as curl http://localhost:5000/tiny_monk.
Please see also Plack::Request, Plack::App::URLMap and HTML::HTML5::Builder, map, Re^4: RFC: Proofread the POD for my HTML elements module and Re^3: RFC: Proofread the POD for my HTML elements module.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|