This document discusses Mojolicious::Lite, a micro web application framework for Perl. It begins by introducing Mojolicious::Lite and positioning it as a framework for small, single-file web apps as opposed to production or complex applications. It then provides an example of a simple Mojolicious::Lite app and explains key aspects like routes, templates, and starting the app. Finally, it briefly mentions some similar Perl web frameworks and provides additional resources.
15. /Mojo.*/
Mojo
“The box!”
Encapsula as complexidades de CGI,
FastCGI, PSGI, HTTP e WebSocket num
s´ m´todo
o e
D´ suporte a frameworks web como
a
Mojolicious e Mojolicious::Lite
16. /Mojo.*/
Mojolicious
“The web in a box!”
framework MVC com API OO Perl
depende apenas de Perl 5.8.1
18. Mojolicious::Lite
Single file micro web apps framework
˜
NAO!
N˜o apropriado para produc˜o, software
a ¸a
comercial, ...
N˜o apropriado para aplicac˜es complexas
a ¸o
19. Mojolicious::Lite
Single file micro web apps framework
˜
NAO!
N˜o apropriado para produc˜o, software
a ¸a
comercial, ...
N˜o apropriado para aplicac˜es complexas
a ¸o
N˜o est´ bem documentado (ainda)
a a
20. $ mojolicious generate lite_app
[exist] ~/folder
[write] ~/folder/myapp.pl
[chmod] myapp.pl 744
$ myapp.pl
...
generate Generate files and directories from templates.
routes Show available routes.
inflate Inflate embedded files to real files.
version Show versions of installed modules.
daemon_prefork Start application w/prefork HTTP 1.1 backend.
fastcgi Start application with FastCGI backend.
daemon Start application with HTTP 1.1 backend.
cgi Start application with CGI backend.
get Get file from URL.
psgi Start application with PSGI backend.
test Run unit tests.
21. $ cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
get ’/’ => ’index’;
get ’/:groovy’ => sub {
my $self = shift;
$self->render_text($self->param(’groovy’), layout => ’funky’);
};
shagadelic;
__DATA__
@@ index.html.ep
% layout ’funky’;
Yea baby!
@@ layouts/funky.html.ep
<!doctype html><html>
<head><title>Funky!</title></head>
<body><%== content %></body>
</html>
22. $ cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
get ’/’ => ’index’;
get ’/:groovy’ => sub {
my $self = shift;
$self->render_text($self->param(’groovy’), layout => ’funky’);
};
shagadelic;
__DATA__
@@ index.html.ep
% layout ’funky’;
Yea baby!
@@ layouts/funky.html.ep
<!doctype html><html>
<head><title>Funky!</title></head>
<body><%== content %></body>
</html>
23. $ cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
get ’/’ => ’index’;
get ’/:groovy’ => sub {
my $self = shift;
$self->render_text($self->param(’groovy’), layout => ’funky’);
};
app->start;
__DATA__
@@ index.html.ep
% layout ’funky’;
Yea baby!
@@ layouts/funky.html.ep
<!doctype html><html>
<head><title>Funky!</title></head>
<body><%== content %></body>
</html>
24. Routes
get ’/’ => ’index’ # GET ’/’
get ’/:groovy’ => sub
# GET ’/anyword’
25. Routes
get ’/’ => ’index’ # GET ’/’
get ’/:groovy’ => sub
# GET ’/anyword’
get ’/perl’ # GET ’/perl’
any [qw/post delete/] ’/bar/:foo’
# ’ POST or DELETE ’/bar/*’
any ’/:foo’ => [foo => qr/+/]
.
# ’/2010’
26. Routes
get ’/’ => ’index’ # GET ’/’
get ’/:groovy’ => sub
# GET ’/anyword’
get ’/perl’ # GET ’/perl’
any [qw/post delete/] ’/bar/:foo’
# ’ POST or DELETE ’/bar/*’
any ’/:foo’ => [foo => qr/+/]
.
# ’/2010’
get ’/number/:num’ => {num => 42}
get ’/path/(*everything)
27. Templates
Sistema de templates pr´prio; ou
o
Template Toolkit, ...