6. Что такое Mojolicious?
• Pure Perl веб-фреймворк
• Без зависимостей (с версии Perl 5.8.1)
• Объектно-ориентированное API (без скрытой магии)
• Поддержка HTTP 1.1, WebSocket, IPv6, SSL, IDNA
• Поддержка CGI, FastCGI, PSGI, Daemon и Prefork
• Веб-фреймворки: Mojo, Mojolicious и Mojolicious::Lite
13. 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 { ... }
14. 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 { ... }
15. 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 { ... }
179. 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;
180. 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;
181. 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;
182. 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;
183. 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;
184. package App;
use base 'Mojolicious';
sub startup {
my $self = shift;
my $r = $self->routes;
$r->route('/:id', id => qr/d+/)
->to('example#welcome');
}
1;
185. 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');
}
}
186. 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');
}
}
187. 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;
221. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
222. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
223. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
224. use Mojolicious::Lite;
post '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
225. use Mojolicious::Lite;
any '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
226. use Mojolicious::Lite;
get '/' => (agent => qr/Firefox/) => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
227. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => {groovy => 42} => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
228. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => [groovy => qr/d+/] => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
229. use Mojolicious::Lite;
ladder sub {}; # auth
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
230. use Mojolicious::Lite;
websocket '/echo' => sub { ... };
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
231. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->renderer->default_handler('epl');
app->start;
232. use Mojolicious::Lite;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render_text( $self->param('groovy') );
};
app->start;
247. Документация
• Пока не очень, зато очень хороший фидбек :)
• Mojolicious::Lite и Mojolicious::Guides
• Mojolicious Handbook на github.com @kvorg
• Mojolicious FAQ на github.com @vti