Александр Сапожников
Челябинск, Южно-Уральский государственный университетMojolicious [моджоли́шес]
Раньше — Mojo
The Comprehensive Perl Archive Network (CPAN)
currently has 104,267 Perl modules in 24,326 distributions, written by 9,537 authors, mirrored on 268 servers.
#!/usr/bin/perl
use CGI qw/:standard/;
Много всякой всячины: сайты и не только
Web in a box
Без лишних зависимостей (начиная с Perl 5.10)
Быстроразвивающийся
Проще в освоении, мало кода, хорошо подходит для небольших сайтов.
# Automatically enables "strict", "warnings" and Perl 5.10 features
use Mojolicious::Lite;
# Route with placeholder
get '/:foo' => sub {
my $self = shift;
my $foo = $self->param('foo');
$self->render(text => "Hello from $foo.");
};
# Start the Mojolicious command system
app->start;./your-app-name
Sat Feb 18 04:31:04 2012 info Mojo::Server::Daemon:316 [26077]: Server listening (http://*:3000)
Server available at http://*:3000.
Sat Feb 18 04:32:57 2012 debug Mojolicious::Plugin::RequestTimer:24 [26119]: GET / (Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/10.10 Chromium/16.0.912.77 Chrome/16.0.912.77 Safari/535.7).
Sat Feb 18 04:32:57 2012 debug Mojolicious::Routes:418 [26119]: Dispatching callback.
Sat Feb 18 04:32:57 2012 debug Mojolicious::Routes:418 [26119]: Dispatching callback.
Use of uninitialized value $w in string eq at /usr/share/perl5/Text/Textile.pm line 1557.
Use of uninitialized value $h in string eq at /usr/share/perl5/Text/Textile.pm line 1558.
Sat Feb 18 04:32:57 2012 debug Mojolicious::Plugin::RequestTimer:48 [26119]: 200 OK (0.054653s, 18.297/s).
Можно — в теле скрипта в секции __DATA__, можно — отдельными файлами.
В шаблонах, по умолчанию — embedded perl (EP):
@@ tags.html.ep
% layout 'default', 'title' => __ 'Tags';
<ul>
% for my $row ( @$rows ) {
% my $link = $row;
% $link =~ tr/ /_/;
<li><a href="<%= url_for "/tags/$link" %>"><%= $row %></a></li>
% }
</ul>
@@ layouts/error.html.ep
<!DOCTYPE html>
<html>
<head>
% $title = b( $title || __ 'ERROR' )->decode('UTF-8')->to_string;
<title><%= $title %></title>
<style type="text/css">
body{background:#fec;color:#000}h1{color:#900}
</style>
</head>
<body>
%= include 'menu';
<%= content %>
</body>
</html>
EPL, POD, TT...
perl -Mojo -e \
'b(g("uwdc.ru")->dom->at("title")->text)->say'
UWDC-2012
perl -Mojo -e 'a("/" => {text => "Hello Mojo!"})->start' daemon
Server available at http://*:3000.
Александр Сапожников
as@susu.ru
shoorick77
shoorick.ru/slide/uwdc-mojo.html
t.co/JMOxJuXU
UWDC-2012