Mojolicious.Веб в коробке!
Анатолий Шарифулин
Sebastian Riedelавтор Catalyst и Mojolicious
http://twitter.com/kraih
Что такоеMojolicious?
Что такое Mojolicious?• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API (без скрытой магии)
• Поддержка HTTP 1.1, WebSocket, IPv6, SSL, IDNA
• Поддержка CGI, FastCGI, PSGI, Daemon и Prefork
• Веб-фреймворки: Mojo, Mojolicious и Mojolicious::Lite
«Fresh code,based upon years of expirience developing
Catalyst»
Pure Perlвеб-фреймворк
• 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
• 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
Mojo::BaseMinimal Base Class For Mojo Projects
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 { ... }
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 { ... }
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 { ... }
• 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
Mojo::ByteStreamByteStream
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;$s->punycode_encode; $s->punycode_decode;
use Mojo::ByteStream 'b';my $s = b('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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
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;$s->punycode_encode; $s->punycode_decode;
• 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
Mojo::TemplatePerlish Templates!
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $count = 10 * 5;
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% use Foo::Bar;
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% if (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%== $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= ucfirst $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} %> </li>% }</ul>
<p><%# comment %></p>
% my $list = $self->stash(‘list’);
<ul>% for (@$list) { <li> <%= $_->{title} xx %> </li>% }</ul>
<p><%# comment %></p>
1 2 3 4 5 6 7 8 91011
Bareword "xx" not allowed while "strict subs" in use at template line 6.
Сообщение об ошибке
Простота PHP, мощь Perl
• 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
Mojo::JSONMinimalistic JSON
my $json = Mojo::JSON->new;
my $string = $json->encode({foo => ‘bar’});
my $hash = $json->decode(‘{"foo":"bar"}’);
my $json = Mojo::JSON->new;
my $string = $json->encode({foo => ‘bar’});
my $hash = $json->decode(‘{"foo":"bar"}’);
• 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
Mojo::LoaderClass loader: load, reload, search
• 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
• 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
• 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
• Mojo::Trasaction
• 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
• Mojo::Trasaction
• 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
• Mojo::Trasaction
• 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
Mojo::IOLoopMinimalistic Reactor For TCP Clients And Servers
Mojo::IOLoopПоддержка IO::KQueue, IO::Epoll,IO::Socket::INET6 и IO::Socket::SSL
my $loop = Mojo::IOLoop->new;
$loop->listen(port => 3000, cb => sub { my ($self, $id) = @_; $self->read_cb ($id => sub { ... });
$self->write_cb($id => sub { ... }););
my $id = $loop->connect(port => 3000, ...);
$loop->start; $loop->stop;
my $loop = Mojo::IOLoop->new;
$loop->listen(port => 3000, cb => sub { my ($self, $id) = @_; $self->read_cb ($id => sub { ... });
$self->write_cb($id => sub { ... }););
my $id = $loop->connect(port => 3000, ...);
$loop->start; $loop->stop;
my $loop = Mojo::IOLoop->new;
$loop->listen(port => 3000, cb => sub { my ($self, $id) = @_; $self->read_cb ($id => sub { ... });
$self->write_cb($id => sub { ... }););
my $id = $loop->connect(port => 3000, ...);
$loop->start; $loop->stop;
my $loop = Mojo::IOLoop->new;
$loop->listen(port => 3000, cb => sub { my ($self, $id) = @_; $self->read_cb ($id => sub { ... });
$self->write_cb($id => sub { ... }););
my $id = $loop->connect(port => 3000, ...);
$loop->start; $loop->stop;
• Mojo::Trasaction
• 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
Mojo::ClientAsync IO HTTP 1.1 And WebSocket Client
my $client = Mojo::Client->new;
$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$self->client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->head( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->post( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->put( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->async->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->get( ‘http://goo.gl’ => sub { my ($self, $tx) = @_; say $tx->res; })->process;
my $client = Mojo::Client->new;
$client->get(‘http://goo.gl’)->res->code;
$client->get( 'http://search.twitter.com/trends.json')->success->json->{trends}->[0]->{name}
my $client = Mojo::Client->new;
$client->get(‘http://goo.gl’)->res->code;
$client->get( 'http://search.twitter.com/trends.json')->success->json->{trends}->[0]->{name}
• Mojo::Trasaction
• 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
• Mojo::Trasaction
• 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
• Mojo::Trasaction
• 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
Всё, что нужно – естьMojolicious – веб в коробке!
Без зависимостейс версии Perl 5.8.1
Mojo runtime
Perl 5.005
Perl 5.006002
Perl 5.008001
Perl 5.010
Объектно-ориентированное
API
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
use overload '""' => sub { shift->to_string },
fallback => 1;
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
Поддержка HTTP 1.1клиент-сервер
Google Summer of Code 2009Pascal Gaudette
MojoX::UserAgent
Поддержка WebSocketклиент-сервер
Протокол WebSocketGoogle, Inc
16 декабря 2009 года
use Mojolicious::Lite;
websocket ‘/echo’ => sub { my $self = shift; $self->receive_message(sub { my ($self, $msg) = @_; $self->send_massage("echo: $msg"); });};
app->start;
use Mojolicious::Lite;
websocket ‘/echo’ => sub { my $self = shift; $self->receive_message(sub { my ($self, $msg) = @_; $self->send_massage("echo: $msg"); });};
app->start;
Mojolicious WebSocket ExamplesИнтересный пример IRC-клиент
Github.com @xantus
Google Summer of Code 2010Performance tuning
the http/websocket implementation
Поддержка CGI, FastCGI, PSGI,
Daemon и Prefork
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
PATH_INFO='/foo/bar' script/mojolicious cgi
Легко тестироватьМожно профилировать код, используя Devel::NYTProf
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
Mojo::Server::FCGIscript/mojolicious fcgiscript/mojolicious fcgi_prefork
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
script/mojolicious daemon --reload
Приложение перезагружается перед запросом,если код был изменен
Обработка сигнала USR1Для обновления кода приложения
script/mojolicious COMMAND [OPTIONS]script/mojolicious cgiscript/mojolicious fastcgiscript/mojolicious psgi script/mojolicious daemonscript/mojolicious daemon_prefork
Веб-фреймворки
MojoBase framework
package App;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('РИТ++ 2010');}1;
package App;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('РИТ++ 2010');}1;
Генерацияmojo-приложения
script/mojo generateapp App
[write ] app/script/app[chmod] app/script/app 744[write ] app/lib/App.pm[write ] app/t/basic.t[mkdir ] app/log
script/app COMMAND [OPTIONS]script/app cgiscript/app fastcgiscript/app psgi script/app daemonscript/app daemon_prefork
script/app COMMAND [OPTIONS]script/app getscript/app test
MVC веб-фреймворки
Mojolicioususe base 'Mojo';
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
Mojolicious::ControllerController Base Class
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render(controller => 'foo', action => 'bar')
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render(template => 'foo/bar')
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render('foo#bar')
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render('foo#bar', format => 'html')
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text('РИТ++ 2010')
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render(text => 'РИТ++ 2010')
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data('binary data')
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render(data => 'binary data')
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json({foo => 'bar'})
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render(json => {foo => 'bar'})
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static('img/logo.png')
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• render
• render_text
• render_data
• render_json
• render_static
• render_not_found / render_exception
• send_message / receive_message
• url_for / redirect_to
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
Mojolicious::PluginsPlugins
• AgentCondition
• Charset
• DefaultHelpers
• EplRenderer
• EpRenderer
• HeaderCondition
• I18n, JsonConfig, PoweredBy
• PodRenderer, RequestTimer
• AgentCondition
• Charset
• DefaultHelpers
• EplRenderer
• EpRenderer
• HeaderCondition
• I18n, JsonConfig, PoweredBy
• PodRenderer, RequestTimer
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• Data::Dumper (Maxdepth: 2, Indent: 1, Terse: 1)
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• $self->req->param( ... )
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• $self->stash( ... )
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• url_for
• dumper
• param
• stash
• layout
• include
• content
• extends
• $self->url_for
• AgentCondition
• Charset
• DefaultHelpers
• EplRenderer
• EpRenderer
• HeaderCondition
• I18n, JsonConfig, PoweredBy
• PodRenderer, RequestTimer
EplRendererEmbed Perl Lite
• расширение шаблонов .epl
• в начале каждого шаблона:% my $self = shift;
• $self->stash('foo')
• AgentCondition
• Charset
• DefaultHelpers
• EplRenderer
• EpRenderer
• HeaderCondition
• I18n, JsonConfig, PoweredBy
• PodRenderer, RequestTimer
EpRendererEmbed Perl
• расширение шаблонов .ep
• кеширование шаблонов со stash-параметрами
• вместо $self->stash('foo') – $foo
• доступны все helpers:
% layout 'default';
% warn dumper $list;
• обработчик по умолчанию в mojolicious
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
• Mojolicous::Controller
• Mojolicious::Plugins
• Mojolicious::Commands
• MojoX::Types
• MojoX::Session
• MojoX::Dispatcher, MojoX::Routes
Генерацияmojolicious-приложения
script/mojolicious generateapp App
[write ] app/script/app[chmod] app/script/app 744[write ] app/lib/App.pm[write ] app/lib/App/Example.pm[write ] app/t/basic.t[mkdir ] app/log
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:id', id => qr/\d+/) ->to('example#welcome');}
1;
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; for ($r->bridge->to('auth#check) { $_->route('/admin')->to('admin#welcome'); }}
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; for ($r->bridge->to('auth#check) { $_->route('/admin')->to('admin#welcome'); }}
package App;use base 'Mojolicious';
sub startup { my $self = shift; my $r = $self->routes; $r->route('/:controller/:action/:id') ->to('example#welcome', id => 1);}
1;
script/mojolicious generateapp App
[write ] app/script/app[chmod] app/script/app 744[write ] app/lib/App.pm[write ] app/lib/App/Example.pm[write ] app/t/basic.t[mkdir ] app/log
package App::Example;use base 'Mojolicious::Controller';
sub welcome { my $self = shift; warn $self->stash(‘id’); $self->render(message => 'РИТ++ 2010');}
1;
package App::Example;use base 'Mojolicious::Controller';
sub welcome { my $self = shift; warn $self->stash(‘id’); $self->render(message => 'РИТ++ 2010');}
1;
package App::Example;use base 'Mojolicious::Controller';
sub welcome { my $self = shift; warn $self->stash(‘id’); $self->render(message => 'РИТ++ 2010');}
1;
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
% layout 'default';
<h2><%= $message %></h2>
<a href="<%== url_for %>">click here</a>
% layout 'default';
<h2><%= $message %></h2>
<a href="<%== url_for %>">click here</a>
% layout 'default';
<h2><%= $self->stash('message') %></h2>
<a href="<%== url_for %>">click here</a>
% layout 'default';
<h2><%= $message %></h2>
<a href="<%== url_for %>">click here</a>
% layout 'default';
<h2><%= stash 'message' %></h2>
<a href="<%== url_for %>">click here</a>
% layout 'default';
<h2><%= $message %></h2>
<a href="<%== url_for %>">click here</a>
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
<!doctype html><html> <head><title>Welcome</title></head> <body> <%== content %> </body></html>
<!doctype html><html> <head><title>Welcome</title></head> <body> <%== content %> </body></html>
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
script/mojolicious generateapp App
[mkdir] app/public[write ] app/templates/not_found.html.ep[write ] app/templates/exception.html.ep[write ] app/templates/layouts/default.html.ep[write ] app/templates/example/welcome.html.ep
Global symbol "$message2" requires explicit package name at (eval 280) line 2.
1: % layout 'default';2: <h2><%= $message2 %></h2>3: ...
{ 'status' => 500, 'message' => ‘РИТ++ 2010’, ...
example/welcome.html.ep
Автоматическая генерация имени шаблона
controller/action.format.handler
Автоматическая генерация имени шаблона
example/welcome.html.ep
Автоматическая генерация имени шаблона
example/welcome.xml.ep
Автоматическая генерация имени шаблона
example/welcome.rss.ep
Автоматическая генерация имени шаблона
example/welcome.json.ep
Автоматическая генерация имени шаблона
example/welcome.html.ep
Автоматическая генерация имени шаблона
example/welcome.html.epl
Автоматическая генерация имени шаблона
example/welcome.html.tt
Автоматическая генерация имени шаблона
example/welcome.html.cttp2 Автоматическая генерация имени шаблона
script/app COMMAND [OPTIONS]script/app cgiscript/app fastcgiscript/app psgi script/app daemonscript/app daemon_prefork
script/app COMMAND [OPTIONS]script/app getscript/app testscript/app routes
Mojolicious::Liteuse base 'Mojolicious';
script/mojolicious generatelite_app lite.pl
[write ] lite.pl[chmod] lite.pl 744
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
post '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
any '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => (agent => qr/Firefox/) => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => {groovy => 42} => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => [groovy => qr/\d+/] => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;ladder sub {}; # authget '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;websocket '/echo' => sub { ... }; get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};app->renderer->default_handler('epl');app->start;
use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy') );};
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>
__DATA__
@@ index.html.ep% layout 'funky';Yea baby!
@@ layouts/funky.html.ep<!doctype html><html> <head><title>Funky!</title></head> <body><%== content %></body></html>
lite.pl COMMAND [OPTIONS]
lite.pl cgilite.pl fastcgilite.pl psgilite.pl daemonlite.pl daemon_prefork
lite.pl COMMAND [OPTIONS]
lite.pl testlite.pl getlite.pl routeslite.pl inflate
«Making hard things possible and everything fun!»
Девиз Mojolicious
«Viva la revolution!»
Девиз Mojolicious #2
«Duct tape for the HTML5 web»
Девиз Mojolicious #3
Mojolicious-модули на CPAN• Mojolicious
• Mojo::Server::FCGI
• AnyEvent::Mojo
• Apache::Mojo
Apache2::Mojo
• Catalyst::Engine::MojoSquatting::On::Mojo
• MojoX::Routes::AsGraph
• MojoX::Log::*
• MojoX::Renderer::*
• TT
• CTTP2, HTP
• XSLT
Mojolicious-модули на CPAN• Mojolicious
• Mojo::Server::FCGI
• AnyEvent::Mojo
• Apache::Mojo
Apache2::Mojo
• Catalyst::Engine::MojoSquatting::On::Mojo
• MojoX::Routes::AsGraph
• MojoX::Log::*
• MojoX::Renderer::*
• TT
• CTTP2, HTP
• XSLT
Mojolicious-модули на CPAN• Mojolicious
• Mojo::Server::FCGI
• AnyEvent::Mojo
• Apache::Mojo
Apache2::Mojo
• Catalyst::Engine::MojoSquatting::On::Mojo
• MojoX::Routes::AsGraph
• MojoX::Log::*
• MojoX::Renderer::*
• TT
• CTTP2, HTP
• XSLT
Mojolicious::Lite vs.
DancerСоревнование
Стабильная версия, совместимость?
Обратная совместимость не гарантируется :)
До первой стабильной версии
Mojolicious 0.999925Последняя версия доступна на github.com
Документация
• Пока не очень, зато очень хороший фидбек :) • Mojolicious::Lite и Mojolicious::Guides
• Mojolicious Handbook на github.com @kvorg
• Mojolicious FAQ на github.com @vti
Полезная информация• http://mojolicious.org
• irc://irc.perl.org/#mojo
• http://groups.google.com/group/mojolicious
• Github: kraih, vti, xantus
• Twitter: @kraih, @vtivti, @sharifulin
• Juick: @vti, @sharifulin
«Особая разновидность современного программиста – программист, изучающий
фреймворки»
«Каждый программист должен сделать 3 вещи: фреймворк, шаблонизатор и событийную машину»
use Mojoliciousor die;
Viva la revolution!
use Perlor die;
JFDI
any ‘/questions’ => sub { shift->render( answer => ‘sharifulin’, ); };
Спасибо за внимание!Это 256й слайдАнатолий Шарифулин