Plack provides a common interface called PSGI (Perl Server Gateway Interface) that allows Perl web applications to run on different web servers. It includes tools like Plackup for running PSGI applications from the command line and middleware for adding functionality. Plack has adapters that allow many existing Perl web frameworks to run under PSGI. It also provides high performance PSGI servers and utilities for building and testing PSGI applications.
1 of 127
More Related Content
Plack perl superglue for web frameworks and servers
54. my $app = sub {
my $env = shift;
return sub {
my $respond = shift;
# You could do some event loop
# to delay response (e.g. Comet)
$respond->([ $status, $header, $body ]);
};
};
55. my $app = sub {
my $env = shift;
return sub {
my $respond = shift;
my $w = $respond->([ $status, $header ]);
$w->write($body);
$w->write($body);
...
$w->close;
};
};
71. my $app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
my $mw = sub {
my $env = shift;
# do something with $env
my $res = $app->($env);
# do something with $res;
return $res;
};
77. use CatApp;
use CGIApp;
my $c1 = sub { CatApp->run };
my $c2 = sub { CGIApp->run_psgi };
use Plack::Builder;
builder {
mount “/cat” => $c1;
mount “/cgi-app” => builder {
enable “StackTrace”;
$c2;
};
}
82. use Plack::Test;
use HTTP::Request::Common;
my $app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi app => $app, client => sub {
my $cb = shift;
my $req = GET “http://localhost/foo”;
my $res = $cb->($req);
# test $res;
};
83. use Plack::Test;
use HTTP::Request::Common;
$Plack::Test::Impl = “Server”;
my $app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi app => $app, client => sub {
my $cb = shift;
my $req = GET “http://localhost/foo”;
my $res = $cb->($req);
# test $res;
};
115. Merge Plack::Request
Becomes a library for middleware writers
Make it work better when created multiple times
116. Summary
• PSGI is an interface, Plack is the code.
• We have many (pretty fast) PSGI servers.
• We have adapters and tools for most web
frameworks.
• Use it!