#!/usr/bin/env perl use Mojolicious::Lite; # Documentation browser under "/perldoc" plugin 'PODRenderer'; sub validate { my $input=shift; $input =~ s/\W/_/g; return $input; }; get '/' => sub { my $c = shift; $c->render('index'); }; get '/view/:ticket' => sub { my $c = shift; my $ticket = validate($c->param('ticket')); $c->render( 'ticketing', ticket => $ticket, ); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title 'Welcome'; Welcome to the Mojolicious real-time web framework! @@ layouts/default.html.ep <!DOCTYPE html> <html> <head><title><%= title %></title></head> <body><%= content %></body> </html> @@ ticketing.html.ep % layout 'default'; % title 'Ticket Viewing'; <h1>This is where the business happens for <%= $ticket %></h1>
Using Mojolicious is a great way to do small web apps. They are well encapsulated and contain the primary functionality like logging, templating, debugging. You start out with one file using mojo generate lite_app <name> and everything (webserver, logic, templates) is in one file. Later there are options for growing into a full fledged module and separating into more manageable aspects if needed../Ticketing get '/view/12312`asdf`' [Mon Jun 22 13:13:10 2015] [debug] Your secret passphrase needs to be +changed!!! [Mon Jun 22 13:13:10 2015] [debug] GET "/view/12312%60asdf%60". [Mon Jun 22 13:13:10 2015] [debug] Routing to a callback. [Mon Jun 22 13:13:10 2015] [debug] Rendering template "ticketing.html. +ep" from DATA section. [Mon Jun 22 13:13:10 2015] [debug] Rendering template "layouts/default +.html.ep" from DATA section. [Mon Jun 22 13:13:10 2015] [debug] 200 OK (0.011596s, 86.237/s). <!DOCTYPE html> <html> <head><title>Ticket Viewing</title></head> <body> <h1>This is where the business happens for 12312_asdf_</h1 +> </body> </html>
In reply to Re: Good Style for Small Apps
by trippledubs
in thread Good Style for Small Apps
by Hermano23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |