Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Good Style for Small Apps

by trippledubs (Deacon)
on Jun 22, 2015 at 18:19 UTC ( [id://1131521]=note: print w/replies, xml ) Need Help??


in reply to Good Style for Small Apps

I accept this way:
#!/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>
./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>
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1131521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found