• Amon2 (Perl5)
• Mojolicious (Perl5)
• Play Framework (Java/Scala)
• Ruby on Rails
• Sinatra (Ruby)
• etc, etc……
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
14(*
http://plackperl.org
5
Slide 28
Slide 28 text
PSGI is an interface between Perl
web applications and web servers, and
Plack is a Perl module and toolkit
that contains PSGI middleware,
helpers and adapters to web servers.
http://plackperl.org
Slide 29
Slide 29 text
ʮϦΫΤετใͷ٧·ͬͨ
IBTIΛड͚औͬͯɺϨεϙϯε
ใͷೖͬͨBSSBZSFGΛฦ͢ʯ
Slide 30
Slide 30 text
Handler
Middleware
%env → $@res
Slide 31
Slide 31 text
return sub {
my %env = shift;
return [200, [], ["body"]];
}
5
Slide 32
Slide 32 text
14(*
https://github.com/supernovus/perl6-psgi
Slide 33
Slide 33 text
return sub(%env) {
return 200, [], ["body"];
}
Slide 34
Slide 34 text
1MBDL
http://plackperl.org
5
Slide 35
Slide 35 text
$SVTU
https://github.com/tokuhirom/p6-Crust
Slide 36
Slide 36 text
Crust is a set of tools for using the PSGI
stack. It contains middleware
components(TBI), and utilities for Web
application frameworks. Crust is like Perl5's
Plack, Ruby's Rack, Python's Paste for WSGI.
https://github.com/tokuhirom/p6-Crust
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
ࢦ͢
Slide 39
Slide 39 text
4JOBUSBMJLFͳ
ܰྔϑϨʔϜϫʔΫͷ
ίϯηϓτ࣮
࠶ܝ
Slide 40
Slide 40 text
JNBHJOF,PTTZ
Slide 41
Slide 41 text
get '/user/:name' do
"You're #{params['name']}!"
end
get '/' => sub {
my ( $self, $c ) = @_;
$c->render('index.tx', { msg => "Hello!" });
};
Sinatra
Kossy
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
4JYBUSB
Slide 44
Slide 44 text
unit module MyWeb;
use Sixatra;
get '/user/:name', -> $c {
"I am " ~ $c.param;
}
get '/html', -> $c {
$c.render('view/page.html');
}
• ϑΟϧλ (before, after)
• ηογϣϯ
• ੩తϑΝΠϧ৴
• DB ଓ
• ίʔυδΣωϨʔλ
See Crust::Middleware::Session
See Crust::Middleware::Static
͕ൃࢄ͢Δ
ؒʹ߹Θͳ͔ͬͨ
ؒʹ߹Θͳ͔ͬͨ
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
%4-
Slide 53
Slide 53 text
unit module MyWeb;
use Sixatra;
get '/user/:name', -> $c {
"I am " ~ $c.param;
}
get '/html', -> $c {
$c.render('view/page.html');
}
࠶ܝ
Slide 54
Slide 54 text
unit class Sixatra::Connection;
has Sixatra::Request $.req;
has Hash $.params;
method render(Str $filename, *@args) {
...
}
Slide 55
Slide 55 text
my class RoutingStaff {
has Callable $.app;
};
sub router($methods, $path, $app) is export {
$ROUTER.add(
@$methods,
$path,
RoutingStaff.new(:$app)
);
}
sub get($path, $app) is export {
router ["GET", "HEAD"], $path, $app;
}
Slide 56
Slide 56 text
ϧʔςΟϯά
Slide 57
Slide 57 text
NFUIPE
QBUI
ˣ
DPOUSPMMFS
QBSBNT
Slide 58
Slide 58 text
No content
Slide 59
Slide 59 text
get '/login' -> $c {
$c.render('view/login-form.html');
}
post '/login' -> $c {
...
$c.redirect(
$c.req.parameters
);
}
Slide 60
Slide 60 text
get '/users/:name' -> $c {
"You are " ~ $c.params;
}
my $match = $ROUTER.match(
$req.method, $req.path-info
);
return 405, [], ['Method Not Allowed']
if $match;
with $match {
my $c = Sixatra::Connection.new(
:$req, :params($match)
);
my $res = $match.app.($c);
...