Mojolicious lite

32
Mini aplica¸ c˜oes web com Mojolicious::Lite Andr´ e Santos [email protected] PtPW 2010 5 de Julho

description

A brief presentation about Mojolicious::Lite, a Perl module to create single file web apps, given at PtPW2010.

Transcript of Mojolicious lite

Page 1: Mojolicious lite

Mini aplicacoes web com

Mojolicious::LiteAndre Santos

[email protected]

PtPW 20105 de Julho

Page 2: Mojolicious lite

Disclaimer

[Web] developer profissional

Perl::Newbie

#{coisas certas} > #{coisas erradas}

Page 3: Mojolicious lite

Disclaimer

[Web] developer profissional

Perl::Newbie

#{coisas certas} > #{coisas erradas}

Page 4: Mojolicious lite

Disclaimer

[Web] developer profissional

Perl::Newbie

#{coisas certas} > #{coisas erradas}

Page 5: Mojolicious lite

Ruby

Ruby on Rails“open source MVC web app framework”

PerlCatalyst(outros)

Page 6: Mojolicious lite

Ruby

Ruby on Rails“open source MVC web app framework”

Perl

Catalyst(outros)

Page 7: Mojolicious lite

RubyRuby on Rails“open source MVC web app framework”

Perl

Catalyst(outros)

Page 8: Mojolicious lite

RubyRuby on Rails“open source MVC web app framework”

PerlCatalyst(outros)

Page 9: Mojolicious lite

Ruby

Sinatrapequenas aplicacoes web

Perl

Mojolicious::Lite“micro web framework”

Page 10: Mojolicious lite

RubySinatrapequenas aplicacoes web

Perl

Mojolicious::Lite“micro web framework”

Page 11: Mojolicious lite

RubySinatrapequenas aplicacoes web

PerlMojolicious::Lite“micro web framework”

Page 12: Mojolicious lite

/Mojo.*/

Mojo

Mojolicious

Mojolicious::Lite

criados por Sebastian RiedelI tambem criador de CatalystI developer RoR

Page 13: Mojolicious lite

/Mojo.*/

Mojo

Mojolicious

Mojolicious::Lite

criados por Sebastian RiedelI tambem criador de CatalystI developer RoR

Page 14: Mojolicious lite

/Mojo.*/

.---------------------------------------------------------------.| Fun! |’---------------------------------------------------------------’.---------------------------------------------------------------.| || .----------------------------------------------’| | .--------------------------------------------.| Application | | Mojolicious::Lite || | ’--------------------------------------------’| | .--------------------------------------------.| | | Mojolicious |’----------------’ ’--------------------------------------------’.---------------------------------------------------------------.| Mojo |’---------------------------------------------------------------’.-------. .-----------. .--------. .------------. .-------------.| CGI | | FastCGI | | PSGI | | HTTP 1.1 | | WebSocket |’-------’ ’-----------’ ’--------’ ’------------’ ’-------------’

Page 15: Mojolicious lite

/Mojo.*/

Mojo“The box!”

Encapsula as complexidades de CGI,

FastCGI, PSGI, HTTP e WebSocket num

so metodo

Da suporte a frameworks web como

Mojolicious e Mojolicious::Lite

Page 16: Mojolicious lite

/Mojo.*/

Mojolicious“The web in a box!”

framework MVC com API OO Perl

depende apenas de Perl 5.8.1

Page 17: Mojolicious lite

Mojolicious::Lite

Single file micro web apps framework

NAO!Nao apropriado para producao, software

comercial, ...

Nao apropriado para aplicacoes complexas

Nao esta bem documentado (ainda)

Page 18: Mojolicious lite

Mojolicious::Lite

Single file micro web apps framework

NAO!Nao apropriado para producao, software

comercial, ...

Nao apropriado para aplicacoes complexas

Nao esta bem documentado (ainda)

Page 19: Mojolicious lite

Mojolicious::Lite

Single file micro web apps framework

NAO!Nao apropriado para producao, software

comercial, ...

Nao apropriado para aplicacoes complexas

Nao esta bem documentado (ainda)

Page 20: Mojolicious lite

$ 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.

Page 21: Mojolicious lite

$ cat myapp.pl#!/usr/bin/env perluse 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>

Page 22: Mojolicious lite

$ cat myapp.pl#!/usr/bin/env perluse 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>

Page 23: Mojolicious lite

$ cat myapp.pl#!/usr/bin/env perluse 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>

Page 24: Mojolicious lite

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)

Page 25: Mojolicious lite

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)

Page 26: Mojolicious lite

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)

Page 27: Mojolicious lite

Templates

Sistema de templates proprio; ou

Template Toolkit, ...

Page 28: Mojolicious lite

Exemploshttp://d.hatena.ne.jp/yukikimoto/20100220/1266588242

Short message BSS (150 loc)

Image BSS (156 loc)

Simple search (106 loc)

Simple real time clock (133 loc)

Simple real time chat (207 loc)

Page 29: Mojolicious lite

$ myapp.pl inflate

[mkdir] ~/folder/templates/layouts

[write] ~/folder/templates/layouts/funky.html.ep

[exist] ~/folder/templates

[write] ~/folder/templates/index.html.ep

Page 30: Mojolicious lite

Trabalho semelhante

Sinatra on Perl,github.com/jtarchie/

sinatra-on-perl

Schenker,github.com/spiritloose/Schenker

Dancer,perldancer.org

Mojolicious::Lite vs Dancerhttp://use.perl.org/~Alias/journal/

Page 31: Mojolicious lite

Trabalho semelhante

Sinatra on Perl,github.com/jtarchie/

sinatra-on-perl

Schenker,github.com/spiritloose/Schenker

Dancer,perldancer.org

Mojolicious::Lite vs Dancerhttp://use.perl.org/~Alias/journal/

Page 32: Mojolicious lite

Questions

o/