7. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (начиная с Perl 5.10)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
8. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
9. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
10. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
11. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
12. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
13. Что такое Mojo?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API
• Поддержка HTTP 1.1 (клиент-сервер)
• CGI, FastCGI, Daemon и Daemon Prefork
• MVC веб-фреймворки:
Mojolicious и Mojolicious::Lite
17 октября 2009 г.
17. Mojo::Base
Minimal Base Class For Mojo Projects
17 октября 2009 г.
18. 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 { ... }
17 октября 2009 г.
19. 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 { ... }
17 октября 2009 г.
20. 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 { ... }
17 октября 2009 г.
56. Объектно-
ориентированное API
17 октября 2009 г.
57. 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!');
}
17 октября 2009 г.
58. 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!');
}
17 октября 2009 г.
59. 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!');
}
17 октября 2009 г.
60. 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!');
}
17 октября 2009 г.
61. use overload '""' => sub
{ shift->to_string },
fallback => 1;
17 октября 2009 г.
62. 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!');
}
17 октября 2009 г.
63. 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!');
}
17 октября 2009 г.
64. 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!');
}
17 октября 2009 г.
68. 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’)
17 октября 2009 г.
106. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
107. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
108. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
109. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
110. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
111. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
112. package TestApp;
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->renderer->default_handler('ep');
my $r = $self->routes;
$r->route('/:controller/:action/:id')
->to(controller => 'example', action =>
'welcome', id => 1);
}
17 октября 2009 г.
113. package TestApp::Example;
use base 'Mojolicious::Controller';
sub welcome {
my $self = shift;
warn $self->stash(‘id’);
$self->render(message => 'Welcome!');
}
1;
17 октября 2009 г.
123. use Mojolicious::Lite;
app->renderer->default_handler('ep');
get '/' => 'index';
any '/:groovy' => sub {
my $self = shift;
$self->render_text($self->stash('groovy'));
};
shagadelic;
17 октября 2009 г.
124. use Mojolicious::Lite;
app->renderer->default_handler('ep');
get '/' => 'index';
any '/:groovy' => sub {
my $self = shift;
$self->render_text($self->stash('groovy'));
};
shagadelic;
17 октября 2009 г.
125. use Mojolicious::Lite;
app->renderer->default_handler('ep');
get '/' => 'index';
any '/:groovy' => sub {
my $self = shift;
$self->render_text($self->stash('groovy'));
};
shagadelic;
17 октября 2009 г.
126. use Mojolicious::Lite;
app->renderer->default_handler('ep');
get '/' => 'index';
any '/:groovy' => sub {
my $self = shift;
$self->render_text($self->stash('groovy'));
};
shagadelic; # shagadelic(‘cgi’)
17 октября 2009 г.
134. 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’);;
};
17 октября 2009 г.
135. 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’);;
};
17 октября 2009 г.
136. test.pl
#!/usr/bin/perl
warn $_ while <STDIN>;
17 октября 2009 г.
144. «мне кажется документацию он никогда
не напишет) он х**рит быстрее, чем
можно писать документацию для него)»
FriendFeed форева!
17 октября 2009 г.
145. Полезная информация
• 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/
17 октября 2009 г.
146. Полезная информация
• 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/
17 октября 2009 г.
148. Полезная информация
• irc://irc.perl.org/#mojo
• http://lists.kraih.com/cgi-bin/mailman/
listinfo/mojo
• Twitter: @kraih, @vtivti, @sharifulin
17 октября 2009 г.
149. Последние новости
• PSGI and Plack is the future of HTTP::Engine that
has support for servers like CGI, FastCGI, Apache,
AnyEvent and Mojo.
• As usually @vtivti is the first to use our newest
Mojolicious feature, ep templates now in
Bootylicious.
• New #mod_perlite release looks great,
#Mojolicious with CGI backend should "just
work™" on it.
• Unicode support in #Mojolicious looks really great
now.
17 октября 2009 г.