The document discusses Plack, a middleware tool for Perl web frameworks, emphasizing its flexibility, plugin architecture, and support for various web application servers. It highlights the evolution from CGI and mod_perl to the modern PSGI (Perl Web Server Gateway Interface), detailing how Plack connects applications to web servers through a standardized interface. Moreover, it mentions various frameworks and middleware available for building and testing web applications using Plack.
Twiggy
Non-blocking web server (like Thin.rb)
based on AnyEvent framework
Starlet
Simpler UNIX HTTP/1.0 Server
Best used with Server::Starter and nginx/lighttpd
Corona uWSGI
Coroutine for each connection http://projects.unbit.it/uwsgi/
based on Coro.pm
Feersum evpsgi
http://github.com/stash/Feersum http://github.com/sekimura/evpsgi
Gepok
http://metacpan/module/Gepok
Pure Perl standalone HTTPS
First released July 2011
83.
Frameworks Apps Your own code
Plack::Middleware
PSGI
Plack::Handler::* (CGI, FCGI, Apache)
Plack::Middleware::A
Plack::Middleware::B
PSGI Compatible App
Request in Response out
P::MW::A P::MW::A
P::MW::B P::MW::B
PSGI App
139.
Plack::Middleware::A
Plack::Middleware::B
PSGI Compatible App
Request in e.g. Redirect Response out
P::MW::A P::MW::A
P::MW::B P::MW::B
PSGI App
140.
Plack::Middleware::A
Plack::Middleware::B
PSGI Compatible App
Request in e.g. Redirect Response out
P::MW::A P::MW::A
e.g. Static
P::MW::B P::MW::B
PSGI App
Assume...
use Plack::Builder;
my $body= ‘<html><body>Hello World</body></html>’;
my $app = sub {
my $self = shift;
return [200, ['Content-Type' => 'text/html'], [ $body ]];
};
165.
Assume...
use Plack::Builder;
my $body= ‘<html><body>Hello World</body></html>’;
my $app = sub {
my $self = shift;
return [200, ['Content-Type' => 'text/html'], [ $body ]];
};
166.
Assume...
use Plack::Builder;
my $body= ‘<html><body>Hello World</body></html>’;
my $app = sub {
my $self = shift;
return [200, ['Content-Type' => 'text/html'], [ $body ]];
};
use CatApp;
use CGIApp;
my$c1 = sub { CatApp->run };
my $c2 = sub { CGIApp->run_psgi };
use Plack::Builder;
return builder {
mount “/cat” => $c1;
mount “/cgi-app” => builder {
enable “StackTrace”;
$c2;
};
}
218.
use CatApp;
use CGIApp;
my$c1 = sub { CatApp->run };
my $c2 = sub { CGIApp->run_psgi };
use Plack::Builder;
return builder {
mount “/cat” => $c1;
mount “/cgi-app” => builder {
enable “StackTrace”;
$c2;
};
}
219.
use CatApp;
use CGIApp;
my$c1 = sub { CatApp->run };
my $c2 = sub { CGIApp->run_psgi };
use Plack::Builder;
return builder {
mount “/cat” => $c1;
mount “/cgi-app” => builder {
enable “StackTrace”;
$c2;
};
}
# Hijack AnyLWP::Useragent requests
LWP::Protocol::PSGI->register($app);
use LWP::Simple;
my $content = get("http://london.pm.org/");
say 'o/' if $content =~ /London Perl Mongers/;
250.
# Hijack AnyLWP::Useragent requests
LWP::Protocol::PSGI->register($app);
use LWP::Simple;
my $content = get("http://london.pm.org/");
say 'o/' if $content =~ /London Perl Mongers/;
251.
# Hijack AnyLWP::Useragent requests
LWP::Protocol::PSGI->register($app);
use LWP::Simple;
my $content = get("http://london.pm.org/");
say 'o/' if $content =~ /London Perl Mongers/;
252.
# Hijack AnyLWP::Useragent requests
LWP::Protocol::PSGI->register($app);
use LWP::Simple;
my $content = get("http://london.pm.org/");
say 'o/' if $content =~ /London Perl Mongers/;
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
258.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
259.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
260.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
261.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
262.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
263.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
264.
use Plack::Test;
use HTTP::Request::Common;
my$app = sub {
my $env = shift;
return [ $status, $header, $body ];
};
test_psgi
app => $app,
client => sub {
my $callback = shift;
my $req = GET “http://localhost/foo”;
my $res = $callback->($req);
ok $res->[0] == ‘200’, ‘Success’;
};
Summary
✦ PSGI isan interface, Plack is the code.
✦ Many fast PSGI servers.
319.
Summary
✦ PSGI isan interface, Plack is the code.
✦ Many fast PSGI servers.
✦ Adapters and tools for frameworks and
webservers.
320.
Summary
✦ PSGI isan interface, Plack is the code.
✦ Many fast PSGI servers.
✦ Adapters and tools for frameworks and
webservers.
✦ An amazing amount of middleware
321.
Summary
✦ PSGI isan interface, Plack is the code.
✦ Many fast PSGI servers.
✦ Adapters and tools for frameworks and
webservers.
✦ An amazing amount of middleware
✦ Used in many production systems