Run a website with Perl? - you should learn how to use Plack. Most Perl web frameworks support it and it makes your life a lot easier and a lot more fun
16. package HelloWorld;
use strict;
use Apache::RequestRec;
use Apache::RequestIO;
use Apache::Const -compile => qw(OK);
sub handler {
my $r = shift;
$r->content_type(‘text/plain’);
$r->print(“Hello World”);
return Apache::Const::OK;
}
1;
17. use FCGI;
my $req = FCGI::Request();
while ($req->Accept >= 0) {
print “Content-Type: text/plainrnrn”;
print “Hello World”;
}
18. package HelloWorld;
use base qw(HTTP::Server::Simple::CGI);
sub handle_request {
my($self, $cgi) = @_;
print “HTTP/1.0 200 OKrn”;
print “Content-Type: text/plainrnrn”;
print “Hello World”;
}
1;
78. 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
82. 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)
138. 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
217. 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;
};
}
249. # Hijack Any LWP::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 Any LWP::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 Any LWP::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 Any LWP::Useragent requests
LWP::Protocol::PSGI->register($app);
use LWP::Simple;
my $content = get("http://london.pm.org/");
say 'o/' if $content =~ /London Perl Mongers/;
257. 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’;
};
318. Summary
✦ PSGI is an interface, Plack is the code.
✦ Many fast PSGI servers.
319. Summary
✦ PSGI is an interface, Plack is the code.
✦ Many fast PSGI servers.
✦ Adapters and tools for frameworks and
webservers.
320. Summary
✦ PSGI is an interface, Plack is the code.
✦ Many fast PSGI servers.
✦ Adapters and tools for frameworks and
webservers.
✦ An amazing amount of middleware
321. Summary
✦ PSGI is an 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