Mojo. The web in a box!

294
Mojo. The web in a box! Saint Perl 2009 English version 6 января 2010 г.

description

English version. Saint Perl 2009

Transcript of Mojo. The web in a box!

Page 1: Mojo. The web in a box!

Mojo.The web in a box!

Saint Perl 2009English version

6 января 2010 г.

Page 2: Mojo. The web in a box!

http://mojolicious.org/6 января 2010 г.

Page 3: Mojo. The web in a box!

Sebastian Riedelавтор Catalyst и Mojohttp://labs.kraih.com/

6 января 2010 г.

Page 4: Mojo. The web in a box!

http://twitter.com/kraih6 января 2010 г.

Page 5: Mojo. The web in a box!

Sebastian Riedelавтор Catalyst и Mojohttp://labs.kraih.com/

6 января 2010 г.

Page 6: Mojo. The web in a box!

Sebastian Riedelcreator of Catalyst and Mojo

http://labs.kraih.com/

6 января 2010 г.

Page 7: Mojo. The web in a box!

Catalyst + Mojo = ?6 января 2010 г.

Page 8: Mojo. The web in a box!

What is Mojo?

6 января 2010 г.

Page 9: Mojo. The web in a box!

What is Mojo?• Pure Perl framework, without

any hidden magick

• No requirements besides Perl 5.8.1

• Very clean and object oriented API

• Full stack HTTP 1.1 (client / server)

• CGI, FastCGI, PSGI, Daemon и Prefork

• Two MVC web frameworks: Mojolicious and Mojolicious::Lite

6 января 2010 г.

Page 10: Mojo. The web in a box!

Pure Perl framework

6 января 2010 г.

Page 11: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 12: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 13: Mojo. The web in a box!

Minimal Base Class For Mojo Projects

Mojo::Base

6 января 2010 г.

Page 14: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return Util->db($self->conf->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 15: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return Util->db($self->conf->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 16: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return Util->db($self->conf->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 17: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 18: Mojo. The web in a box!

ByteStream

Mojo::ByteStream

6 января 2010 г.

Page 19: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 20: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 21: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 22: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 23: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 24: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 25: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 26: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 27: Mojo. The web in a box!

use Mojo::ByteStream;my $s = Mojo::ByteStream->new('foo_bar');

$s->camelize; $s->decamelize;$s->b64_encode; $s->b64_decode;$s->encode('utf8'); $s->decode('utf8');$s->html_escape; $s->html_unescape;$s->qp_encode; $s->qp_decode;$s->quote; $stream->unquote;$s->url_escape; $s->url_unescape;$s->xml_escape;

6 января 2010 г.

Page 28: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 29: Mojo. The web in a box!

Perlish Templates!

Mojo::Template

6 января 2010 г.

Page 30: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 31: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 32: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 33: Mojo. The web in a box!

%= my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 34: Mojo. The web in a box!

%== my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 35: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 36: Mojo. The web in a box!

% use Foo::Bar;

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 37: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 38: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 39: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 40: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 41: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%== $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 42: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <% my $foo = $_->{id} + 100500; %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 43: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <% my $foo = $_->{id} + 100500; %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 44: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 45: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 46: Mojo. The web in a box!

% my $list = $self->stash(‘list’);

<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>

<p><%# comment %></p>

6 января 2010 г.

Page 47: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 48: Mojo. The web in a box!

Minimalistic JSON

Mojo::JSON

6 января 2010 г.

Page 49: Mojo. The web in a box!

my $json = Mojo::JSON->new;

my $string = $json->encode({foo => ‘bar’});

my $hash = $json->decode(‘{"foo":"bar"}’);

6 января 2010 г.

Page 50: Mojo. The web in a box!

my $json = Mojo::JSON->new;

my $string = $json->encode({foo => ‘bar’});

my $hash = $json->decode(‘{"foo":"bar"}’);

6 января 2010 г.

Page 51: Mojo. The web in a box!

my $json = Mojo::JSON->new;

my $string = $json->encode({foo => ‘bar’});

my $hash = $json->decode(‘{"foo":"bar"}’);

6 января 2010 г.

Page 52: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 53: Mojo. The web in a box!

Class loader: load, reload, search

Mojo::Loader

6 января 2010 г.

Page 54: Mojo. The web in a box!

Class loader: load, reload, search

Mojo::Loader

6 января 2010 г.

Page 55: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 56: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 57: Mojo. The web in a box!

• Mojo::Base

• Mojo::ByteStream

• Mojo::Template, Mojo::JSON

• Mojo::Loader, Mojo::Log, Mojo::Path

• Mojo::URL, Mojo::Parameters, Mojo::Content

• Mojo::Message::Request, Mojo::Message::Response,Mojo::Headers, Mojo::Cookie, Mojo::Date

6 января 2010 г.

Page 58: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 59: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 60: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 61: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 62: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 63: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 64: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->post( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 65: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->head( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 66: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->put( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 67: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 68: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 69: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 70: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 71: Mojo. The web in a box!

my $client = Mojo::Client->new;

$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;

6 января 2010 г.

Page 72: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 73: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 74: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 75: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 76: Mojo. The web in a box!

• Mojo::Trasaction, Mojo::Stateful

• Mojo::IOLoop

• Mojo::Client, Mojo::Server

• Mojo::Server::CGI, Mojo::Server::FastCGI

• Mojo::Server::PSGI

• Mojo::Server::Daemon и ::Prefork

• Mojo::Command

• Mojo::Command::Generate и ~ Server

6 января 2010 г.

Page 77: Mojo. The web in a box!

Mojo is the web in a box!

6 января 2010 г.

Page 78: Mojo. The web in a box!

No requirementsbesides Perl 5.8.1

6 января 2010 г.

Page 79: Mojo. The web in a box!

Mojo runtime6 января 2010 г.

Page 80: Mojo. The web in a box!

Perl 5.0056 января 2010 г.

Page 81: Mojo. The web in a box!

Perl 5.0060026 января 2010 г.

Page 82: Mojo. The web in a box!

Perl 5.0080016 января 2010 г.

Page 83: Mojo. The web in a box!

Mojo Perl 5.0106 января 2010 г.

Page 84: Mojo. The web in a box!

Object oriented API

6 января 2010 г.

Page 85: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 86: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 87: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 88: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 89: Mojo. The web in a box!

use overload '""' => sub { shift->to_string },

fallback => 1;

6 января 2010 г.

Page 90: Mojo. The web in a box!

GET / HTTP/1.1Connection: keep-aliveAccept: text/html, application/xhtml, ....Accept-Charset: windows-1251, utf-8; ...Accept-Encoding: gzip,deflateAccept-Language: ru,en-us;q=0.7,en;q=0.3Host: localhost:3000User-Agent: Mozilla/5.0 (Macintosh; ...Content-Length: 0Keep-Alive: 300

6 января 2010 г.

Page 91: Mojo. The web in a box!

GET / HTTP/1.1Connection: keep-aliveAccept: text/html, application/xhtml, ....Accept-Charset: windows-1251, utf-8; ...Accept-Encoding: gzip,deflateAccept-Language: ru,en-us;q=0.7,en;q=0.3Host: localhost:3000User-Agent: Mozilla/5.0 (Macintosh; ...Content-Length: 0Keep-Alive: 300

6 января 2010 г.

Page 92: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 93: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 94: Mojo. The web in a box!

A generation of the mojo app

6 января 2010 г.

Page 95: Mojo. The web in a box!

mojo generate app TestMojo

[mkdir] test_mojo/script[write] test_mojo/script/test_mojo[chmod] test_mojo/script/test_mojo 744[mkdir] test_mojo/lib[write] test_mojo/lib/TestMojo.pm[mkdir] test_mojo/t[write] test_mojo/t/basic.t

6 января 2010 г.

Page 96: Mojo. The web in a box!

mojo generate app TestMojo

[mkdir] test_mojo/script[write] test_mojo/script/test_mojo[chmod] test_mojo/script/test_mojo 744[mkdir] test_mojo/lib[write] test_mojo/lib/TestMojo.pm[mkdir] test_mojo/t[write] test_mojo/t/basic.t

6 января 2010 г.

Page 97: Mojo. The web in a box!

use FindBin;

use lib "$FindBin::Bin/../lib";use lib "$FindBin::Bin/../../lib";

# Application$ENV{MOJO_APP} ||= 'TestMojo';

use Mojo::Commands;Mojo::Commands->start; # ->start(‘cgi’)

6 января 2010 г.

Page 98: Mojo. The web in a box!

mojo generate app TestMojo

[mkdir] test_mojo/script[write] test_mojo/script/test_mojo[chmod] test_mojo/script/test_mojo 744[mkdir] test_mojo/lib[write] test_mojo/lib/TestMojo.pm[mkdir] test_mojo/t[write] test_mojo/t/basic.t

6 января 2010 г.

Page 99: Mojo. The web in a box!

package TestMojo;use base 'Mojo';

sub handler { my ($self, $tx) = @_; warn $tx->req; warn $tx->req->url; $tx->res->headers ->content_type('text/plain'); $tx->res->body('Hello Mojo!');}

6 января 2010 г.

Page 100: Mojo. The web in a box!

mojo generate app TestMojo

[mkdir] test_mojo/script[write] test_mojo/script/test_mojo[chmod] test_mojo/script/test_mojo 744[mkdir] test_mojo/lib[write] test_mojo/lib/TestMojo.pm[mkdir] test_mojo/t[write] test_mojo/t/basic.t

6 января 2010 г.

Page 101: Mojo. The web in a box!

#!/usr/bin/env perl

use strict;use warnings;

use Test::More tests => 1;

use_ok('TestMojo');

6 января 2010 г.

Page 102: Mojo. The web in a box!

Full stack HTTP 1.1

6 января 2010 г.

Page 103: Mojo. The web in a box!

6 января 2010 г.

Page 104: Mojo. The web in a box!

MojoX::UserAgentPascal Gaudette

Thanks to the Google of Summer Code 2009!

6 января 2010 г.

Page 105: Mojo. The web in a box!

CGI, FastCGI, PSGI, Daemon, Prefork

support

6 января 2010 г.

Page 106: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80

6 января 2010 г.

Page 107: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80

6 января 2010 г.

Page 108: Mojo. The web in a box!

PATH_INFO='/' script/test_mojo cgi

Easy checkCan profile the mojo app using Devel::NYTProf

6 января 2010 г.

Page 109: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80

6 января 2010 г.

Page 110: Mojo. The web in a box!

Mojo::Server::FCGIscript/test_mojo fcgiscript/test_mojo fcgi_prefork

6 января 2010 г.

Page 111: Mojo. The web in a box!

Mojo::Server::FCGIscript/test_mojo fcgiscript/test_mojo fcgi_prefork

6 января 2010 г.

Page 112: Mojo. The web in a box!

Mojo::Server::FCGIscript/test_mojo fcgiscript/test_mojo fcgi_prefork

6 января 2010 г.

Page 113: Mojo. The web in a box!

nginx + fcgi_prefork

6 января 2010 г.

Page 114: Mojo. The web in a box!

location / { fastcgi_pass 127.0.0.1:3000; fastcgi_param MOJO_APP App; fastcgi_param SCRIPT_NAME http://127.0.0.1:3000; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;}

6 января 2010 г.

Page 115: Mojo. The web in a box!

location / { fastcgi_pass 127.0.0.1:3000; fastcgi_param MOJO_APP App; fastcgi_param SCRIPT_NAME http://127.0.0.1:3000; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;}

6 января 2010 г.

Page 116: Mojo. The web in a box!

location / { fastcgi_pass 127.0.0.1:3000; fastcgi_param MOJO_APP App; fastcgi_param SCRIPT_NAME http://127.0.0.1:3000; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;}

6 января 2010 г.

Page 117: Mojo. The web in a box!

location / { fastcgi_pass 127.0.0.1:3000; fastcgi_param MOJO_APP App; fastcgi_param SCRIPT_NAME http://127.0.0.1:3000; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;}

6 января 2010 г.

Page 118: Mojo. The web in a box!

location / { fastcgi_pass 127.0.0.1:3000; fastcgi_param MOJO_APP App; fastcgi_param SCRIPT_NAME http://127.0.0.1:3000; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;}

6 января 2010 г.

Page 119: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80

6 января 2010 г.

Page 120: Mojo. The web in a box!

MOJO_RELOAD=1 script/test_mojo daemon

Application code will reload on each request

6 января 2010 г.

Page 121: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80

6 января 2010 г.

Page 122: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80script/test_mojo test

6 января 2010 г.

Page 123: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80script/test_mojo testscript/test_mojo get

6 января 2010 г.

Page 124: Mojo. The web in a box!

script/test_mojo COMMAND [OPTIONS]

script/test_mojo cgiscript/test_mojo fastcgiscript/test_mojo daemonscript/test_mojo daemon_prefork --port 80script/test_mojo testscript/test_mojo get http://goo.gl

6 января 2010 г.

Page 125: Mojo. The web in a box!

MVC web frameworks

6 января 2010 г.

Page 126: Mojo. The web in a box!

Mojolicioususe base 'Mojo';

6 января 2010 г.

Page 127: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 128: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 129: Mojo. The web in a box!

Controller Base Class

Mojolicious::Controller

6 января 2010 г.

Page 130: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 131: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 132: Mojo. The web in a box!

• render(tempate => ‘foo/bar’)

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 133: Mojo. The web in a box!

• render(controller => ‘foo’, action => ‘bar’)

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 134: Mojo. The web in a box!

• render(‘foo/bar’, format => ‘html)

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 135: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 136: Mojo. The web in a box!

• render

• render(text => ‘Saint Perl 2009’)

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 137: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 138: Mojo. The web in a box!

• render

• render_text

• render(json => {foo => ‘bar’})

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 139: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 140: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 141: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 142: Mojo. The web in a box!

• render

• render_text

• render_json

• render_inner

• render_partial

• pause / resume

• redirect_to / url_for

6 января 2010 г.

Page 143: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 144: Mojo. The web in a box!

Plugin Base Class

Mojolicious::Plugin

6 января 2010 г.

Page 145: Mojo. The web in a box!

Plugins: load_plugin, add_hook, run_hook

Mojolicious::Plugins

6 января 2010 г.

Page 146: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 147: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 148: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 149: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 150: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 151: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 152: Mojo. The web in a box!

• Data::Dumper (Maxdepth: 2, Indent: 1, Terse: 1)

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 153: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 154: Mojo. The web in a box!

• dumper

• $self->req->param(...)

• layout

• include

• content

• extends

6 января 2010 г.

Page 155: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 156: Mojo. The web in a box!

• dumper

• param

• $self->stash(layout => ...)

• include

• content

• extends

6 января 2010 г.

Page 157: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 158: Mojo. The web in a box!

• dumper

• param

• layout

• $self->render_partial(...)

• content

• extends

6 января 2010 г.

Page 159: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 160: Mojo. The web in a box!

• dumper

• param

• layout

• include

• $self->render_inner(...)

• extends

6 января 2010 г.

Page 161: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• extends

6 января 2010 г.

Page 162: Mojo. The web in a box!

• dumper

• param

• layout

• include

• content

• $self->stash(extends => ...)

6 января 2010 г.

Page 163: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 164: Mojo. The web in a box!

• extention of temlplates is .epl

• my $self = shift;

• $self->stash(foo => ‘bar’)

6 января 2010 г.

Page 165: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 166: Mojo. The web in a box!

• extention of temlplates is .ep

• cashing templates with stash parameters

• $self->stash(foo => ‘bar’) – $foo

• any helpers

• default handler

6 января 2010 г.

Page 167: Mojo. The web in a box!

• AgentCondition

• Charset

• DefaultHelpers

• EpRenderer

• EplRenderer

• RequestTimer

6 января 2010 г.

Page 168: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 169: Mojo. The web in a box!

script/test_app COMMAND [OPTIONS]

script/test_app cgiscript/test_app fastcgiscript/test_app daemonscript/test_app daemon_prefork --port 80script/test_app testscript/test_app get

6 января 2010 г.

Page 170: Mojo. The web in a box!

script/test_app COMMAND [OPTIONS]

script/test_app cgiscript/test_app fastcgiscript/test_app daemonscript/test_app daemon_prefork --port 80script/test_app testscript/test_app getscritp/test_app routes

6 января 2010 г.

Page 171: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 172: Mojo. The web in a box!

• Mojolicous::Controller

• Mojolicious::Plugin

• Mojolicious::Commands

• MojoX::Types

• MojoX::Dispatcher, MojoX::Routes

6 января 2010 г.

Page 173: Mojo. The web in a box!

A generationthe mojolicious app

6 января 2010 г.

Page 174: Mojo. The web in a box!

mojolicious generate app TestApp

6 января 2010 г.

Page 175: Mojo. The web in a box!

[mkdir] test_app/script[write] test_app/script/test_app[chmod] test_app/script/test_app 744[mkdir] test_app/lib[write] test_app/lib/TestApp.pm[mkdir] test_app/lib/TestApp[write] test_app/lib/TestApp/Example.pm[mkdir] test_app/t[write] test_app/t/basic.t[mkdir] test_app/log[mkdir] test_app/public[write] test_app/public/404.html[exist] test_app/public[write] test_app/public/500.html

6 января 2010 г.

Page 176: Mojo. The web in a box!

[mkdir] test_app/script[write] test_app/script/test_app[chmod] test_app/script/test_app 744[mkdir] test_app/lib[write] test_app/lib/TestApp.pm[mkdir] test_app/lib/TestApp[write] test_app/lib/TestApp/Example.pm[mkdir] test_app/t[write] test_app/t/basic.t[mkdir] test_app/log[mkdir] test_app/public[write] test_app/public/404.html[exist] test_app/public[write] test_app/public/500.html

6 января 2010 г.

Page 177: Mojo. The web in a box!

[mkdir] test_app/script[write] test_app/script/test_app[chmod] test_app/script/test_app 744[mkdir] test_app/lib[write] test_app/lib/TestApp.pm[mkdir] test_app/lib/TestApp[write] test_app/lib/TestApp/Example.pm[mkdir] test_app/t[write] test_app/t/basic.t[mkdir] test_app/log[mkdir] test_app/public[write] test_app/public/404.html[exist] test_app/public[write] test_app/public/500.html

6 января 2010 г.

Page 178: Mojo. The web in a box!

[mkdir] test_app/script[write] test_app/script/test_app[chmod] test_app/script/test_app 744[mkdir] test_app/lib[write] test_app/lib/TestApp.pm[mkdir] test_app/lib/TestApp[write] test_app/lib/TestApp/Example.pm[mkdir] test_app/t[write] test_app/t/basic.t[mkdir] test_app/log[mkdir] test_app/public[write] test_app/public/404.html[exist] test_app/public[write] test_app/public/500.html

6 января 2010 г.

Page 179: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 180: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 181: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 182: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 183: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 184: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 185: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->bridge->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 186: Mojo. The web in a box!

package TestApp;

use base 'Mojolicious';sub startup { my $self = shift;

my $r = $self->routes; $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1);}

6 января 2010 г.

Page 187: Mojo. The web in a box!

package TestApp::Example;

use base 'Mojolicious::Controller';sub welcome { my $self = shift; warn $self->stash(‘id’); $self->render(message => 'Welcome!');}

1;

6 января 2010 г.

Page 188: Mojo. The web in a box!

[exist] test_app/public[write] test_app/public/index.html[mkdir] test_app/templates[write] test_app/templates/exception.html.ep[write] test_app/templates/not_found.html.ep[mkdir] test_app/templates/layouts[write] test_app/templates/layouts/default.html.ep[mkdir] test_app/templates/example[write] test_app/templates/example/welcome.html.ep

6 января 2010 г.

Page 189: Mojo. The web in a box!

[exist] test_app/public[write] test_app/public/index.html[mkdir] test_app/templates[write] test_app/templates/exception.html.ep[write] test_app/templates/not_found.html.ep[mkdir] test_app/templates/layouts[write] test_app/templates/layouts/default.html.ep[mkdir] test_app/templates/example[write] test_app/templates/example/welcome.html.ep

6 января 2010 г.

Page 190: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 191: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 192: Mojo. The web in a box!

controller/welcome.html.ep

Path to the template

6 января 2010 г.

Page 193: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 194: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 195: Mojo. The web in a box!

example/action.html.ep

Path to the template

6 января 2010 г.

Page 196: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 197: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 198: Mojo. The web in a box!

example/welcome.html.handler

Path to the template

6 января 2010 г.

Page 199: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 200: Mojo. The web in a box!

example/welcome.html.epl

Path to the template

6 января 2010 г.

Page 201: Mojo. The web in a box!

example/welcome.html.tt

Path to the template

6 января 2010 г.

Page 202: Mojo. The web in a box!

example/welcome.html.ht

Path to the template

6 января 2010 г.

Page 203: Mojo. The web in a box!

example/welcome.html.pro

Path to the template

6 января 2010 г.

Page 204: Mojo. The web in a box!

example/welcome.html.ctpp2

Path to the template

6 января 2010 г.

Page 205: Mojo. The web in a box!

example/welcome.html.foo

Path to the template

6 января 2010 г.

Page 206: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 207: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 208: Mojo. The web in a box!

example/welcome.format.ep

Path to the template

6 января 2010 г.

Page 209: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 210: Mojo. The web in a box!

example/welcome.xml.ep

Path to the template

6 января 2010 г.

Page 211: Mojo. The web in a box!

example/welcome.rss.ep

Path to the template

6 января 2010 г.

Page 212: Mojo. The web in a box!

example/welcome.json.ep

Path to the template

6 января 2010 г.

Page 213: Mojo. The web in a box!

example/welcome.yaml.ep

Path to the template

6 января 2010 г.

Page 214: Mojo. The web in a box!

example/welcome.mail.ep

Path to the template

6 января 2010 г.

Page 215: Mojo. The web in a box!

example/welcome.bar.ep

Path to the template

6 января 2010 г.

Page 216: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 217: Mojo. The web in a box!

example/welcome.html.ep

Path to the template

6 января 2010 г.

Page 218: Mojo. The web in a box!

controller/action.format.handler

Path to the template

6 января 2010 г.

Page 219: Mojo. The web in a box!

% layout 'default';

<h2><%= $message %></h2>

<a href="<%== url_for %>">click here</a>

6 января 2010 г.

Page 220: Mojo. The web in a box!

[exist] test_app/public[write] test_app/public/index.html[mkdir] test_app/templates[write] test_app/templates/exception.html.ep[write] test_app/templates/not_found.html.ep[mkdir] test_app/templates/layouts[write] test_app/templates/layouts/default.html.ep[mkdir] test_app/templates/example[write] test_app/templates/example/welcome.html.ep

6 января 2010 г.

Page 221: Mojo. The web in a box!

<!doctype html><html> <head><title>Welcome</title></head> <body> <%== content %> </body></html>

6 января 2010 г.

Page 222: Mojo. The web in a box!

[exist] test_app/public[write] test_app/public/index.html[mkdir] test_app/templates[write] test_app/templates/exception.html.ep[write] test_app/templates/not_found.html.ep[mkdir] test_app/templates/layouts[write] test_app/templates/layouts/default.html.ep[mkdir] test_app/templates/example[write] test_app/templates/example/welcome.html.ep

6 января 2010 г.

Page 223: Mojo. The web in a box!

Global symbol "$message2" requires explicit package name at (eval 280) line 2.

1: % layout 'default';2: <h2><%= $message2 %></h2>3: ...

{ 'status' => 500, 'message' => ‘Saint Perl 2009’, ... }

6 января 2010 г.

Page 224: Mojo. The web in a box!

$ENV{MOJO_MODE}Default value is development

6 января 2010 г.

Page 225: Mojo. The web in a box!

[exist] test_app/public[write] test_app/public/index.html[mkdir] test_app/templates[write] test_app/templates/exception.html.ep[write] test_app/templates/not_found.html.ep[mkdir] test_app/templates/layouts[write] test_app/templates/layouts/default.html.ep[mkdir] test_app/templates/example[write] test_app/templates/example/welcome.html.ep

6 января 2010 г.

Page 226: Mojo. The web in a box!

Mojolicious::Liteuse base 'Mojolicious';

6 января 2010 г.

Page 227: Mojo. The web in a box!

mojolicious generate lite_app test_lite

6 января 2010 г.

Page 228: Mojo. The web in a box!

[write] test_lite[chmod] test_lite 744

6 января 2010 г.

Page 229: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 230: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 231: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 232: Mojo. The web in a box!

use Mojolicious::Lite;

post '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 233: Mojo. The web in a box!

use Mojolicious::Lite;

any '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 234: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 235: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => [groovy => qr/\d+/] => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 236: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => {groovy => 42} => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 237: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => (agent=>qr/Firefox/) => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 238: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};app->renderer->default_handler(‘epl’);shagadelic;

6 января 2010 г.

Page 239: Mojo. The web in a box!

use Mojolicious::Lite;ladder sub { ... }; # authget '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic;

6 января 2010 г.

Page 240: Mojo. The web in a box!

use Mojolicious::Lite;

get '/' => 'index';

any '/:groovy' => sub { my $self = shift; $self->render_text($self->stash('groovy'));};

shagadelic; # shagadelic(‘cgi’)

6 января 2010 г.

Page 241: Mojo. The web in a box!

__DATA__

@@ index.html.ep% layout 'funky';Yea baby!

@@ layouts/funky.html.ep<!doctype html><html> <body> <%== content %> </body></html>

6 января 2010 г.

Page 242: Mojo. The web in a box!

Mojo modules on CPAN

6 января 2010 г.

Page 243: Mojo. The web in a box!

Mojo modules on CPAN

• Mojo

• Mojo::Server::FCGI

• AnyEvent::Mojo

• Apache::Mojo, Apache2::Mojo

• Catalyst::Engine::Mojo,Squatting::On::Mojo

• MojoX::UserAgent

• MojoX::Routes::AsGraph

• MojoX::Session

• MojoX::Log::*

• MojoX::Renderer::*

• JSON

• TT

• CTTP2, HTP

6 января 2010 г.

Page 244: Mojo. The web in a box!

Mojo Guide StyleRules

6 января 2010 г.

Page 245: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 246: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 247: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 248: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 249: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 250: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama

Mojo Guide Style

6 января 2010 г.

Page 251: Mojo. The web in a box!

• Keep it simple, no magick unless absolutely nessary

• Code should be written with a Perl6 port in mind

• It’s not a feature without a test

• Only add prereqs if absolutely necessary

• No inline POD

• No spaghetti code

• Every files should contain at least one quote fromThe Simpsons or Futurama :)

Mojo Guide Style

6 января 2010 г.

Page 252: Mojo. The web in a box!

The Simpsons or Futurama6 января 2010 г.

Page 253: Mojo. The web in a box!

Stable version and backwards compatibility

6 января 2010 г.

Page 254: Mojo. The web in a box!

Mojo 0.999915The latest version of Mojo always available

on github.com

6 января 2010 г.

Page 255: Mojo. The web in a box!

http://github.com/kraih/mojo6 января 2010 г.

Page 256: Mojo. The web in a box!

Nobackwards

compatibility :)Until the first stable version will not be released

6 января 2010 г.

Page 257: Mojo. The web in a box!

First critical bug

6 января 2010 г.

Page 258: Mojo. The web in a box!

get ‘/bug/’ => sub { my $self = shift;

# open my $fh, ‘|-’, ‘/usr/sbin/sendmail -t’; open my $fh, ‘|-’, ‘perl test.pl’; print $fh join "\n", 'To: sharifulin at gmail.com', 'Subject: Test', '', 'Test!'; $self->render_text(‘Test’);;};

6 января 2010 г.

Page 259: Mojo. The web in a box!

get ‘/bug/’ => sub { my $self = shift;

# open my $fh, ‘|-’, ‘/usr/sbin/sendmail -t’; open my $fh, ‘|-’, ‘perl test.pl’; print $fh join "\n", 'To: sharifulin at gmail.com', 'Subject: Test', '', 'Test!'; $self->render_text(‘Test’);;};

6 января 2010 г.

Page 260: Mojo. The web in a box!

test.pl

#!/usr/bin/perlwarn $_ while <STDIN>;

6 января 2010 г.

Page 261: Mojo. The web in a box!

script/test_bug daemon # OK

6 января 2010 г.

Page 262: Mojo. The web in a box!

script/test_bug daemon # OKscript/test_bug daemon_prefork # DIE

6 января 2010 г.

Page 263: Mojo. The web in a box!

Mojo::Server::Daemon::Prefork #323:

$SIG{HUP } = $SIG{INT } = $SIG{CHLD} = $SIG{TERM} = sub { exit 0 };

6 января 2010 г.

Page 264: Mojo. The web in a box!

Mojo::Server::Daemon::Prefork #323:

$SIG{HUP } = $SIG{INT } = $SIG{CHLD} = $SIG{TERM} = sub { exit 0 };

6 января 2010 г.

Page 265: Mojo. The web in a box!

Mojo::Server::Daemon::Prefork #323:

$SIG{HUP } = $SIG{INT } = $SIG{TERM } = sub { exit 0 };

$SIG{CHLD} = ‘IGNORE’;

6 января 2010 г.

Page 266: Mojo. The web in a box!

Second critical bug

6 января 2010 г.

Page 267: Mojo. The web in a box!

MOJO_RELOAD, daemon и attr

6 января 2010 г.

Page 268: Mojo. The web in a box!

MOJO_RELOAD=1 script/test_bug2 daemon# OK

6 января 2010 г.

Page 269: Mojo. The web in a box!

MOJO_RELOAD=1 script/test_bug2 daemon# sometimes ERROR

6 января 2010 г.

Page 270: Mojo. The web in a box!

script/test_bug2 daemon_prefork # OK

6 января 2010 г.

Page 271: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return Util->db($self->conf->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 272: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return Util->db($self->conf->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 273: Mojo. The web in a box!

package App;use base ‘Mojo::Base’;

__PACKAGE__->attr(conf => sub { return do ‘conf/app.conf’;});__PACKAGE__->attr(db => sub { my $self = shift; return $::DB ||= Util->db(...->{'db'});});

sub dispatch { ... }6 января 2010 г.

Page 274: Mojo. The web in a box!

Documentation

6 января 2010 г.

Page 275: Mojo. The web in a box!

DocumentationLess than necessary :)

6 января 2010 г.

Page 276: Mojo. The web in a box!

Links

• http://mojolicious.org

• http://labs.kraih.com/blog/

• http://search.cpan.org/dist/Mojo/

• http://github.com/kraih/mojo

• http://sharifulin.livejournal.com/tag/mojo

• http://getbootylicious.org/

6 января 2010 г.

Page 277: Mojo. The web in a box!

Links

• http://mojolicious.org

• http://labs.kraih.com/blog/

• http://search.cpan.org/dist/Mojo/

• http://github.com/kraih/mojo

• http://sharifulin.livejournal.com/tag/mojo

• http://getbootylicious.org/

6 января 2010 г.

Page 278: Mojo. The web in a box!

Bootylicious6 января 2010 г.

Page 279: Mojo. The web in a box!

Bootylicious6 января 2010 г.

Page 281: Mojo. The web in a box!

The latest news

• PSGI and Plack is the future of HTTP::Engine that has support for servers like CGI, FastCGI, Apache, AnyEvent and Mojo.

• New #mod_perlite release looks great, #Mojolicious with CGI backend should "just work™" on it.

• Slowly starting with documentation work, crazy how much #Mojolicious has grown recently, looks like it needs a few extra chapters now. :)

• Added native #PSGI support to #Mojolicious

6 января 2010 г.

Page 282: Mojo. The web in a box!

My experience in the development

using Mojo

6 января 2010 г.

Page 283: Mojo. The web in a box!

Mojolicious + MojoX::Renderer::TT6 января 2010 г.

Page 284: Mojo. The web in a box!

Mojo + JSON6 января 2010 г.

Page 285: Mojo. The web in a box!

Mojolicious::Lite + MojoX::Renderer::JSON

6 января 2010 г.

Page 286: Mojo. The web in a box!

Mojolicious::Lite + MojoX::Renderer::JSON + RSS

6 января 2010 г.

Page 287: Mojo. The web in a box!

Mojolicious + Mojo::Template6 января 2010 г.

Page 288: Mojo. The web in a box!

Mojolicious + EpRenderer~7 projects

6 января 2010 г.

Page 289: Mojo. The web in a box!

«Making hard things possible and everything fun!»The motto of Mojolicious

6 января 2010 г.

Page 290: Mojo. The web in a box!

use Mojoor die

6 января 2010 г.

Page 291: Mojo. The web in a box!

use Perlor die

6 января 2010 г.

Page 292: Mojo. The web in a box!

JFDI

6 января 2010 г.

Page 293: Mojo. The web in a box!

any ‘/questions’ => sub { shift->render( answer => ‘sharifulin’, );};shagadelic;

6 января 2010 г.

Page 294: Mojo. The web in a box!

Thanks!Anatoly SharifulinRostovOnDon.pm

6 января 2010 г.