"...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»


In reply to Re^3: How do I run a loop within a PSGI application by karlgoethebier
in thread How do I run a loop within a PSGI application by tiny_monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.