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
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;
use FCGI;
my $req = FCGI::Request();
while ($req->Accept >= 0) {
print “Content-Type: text/plainrnrn”;
print “Hello World”;
}
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;
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
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
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
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
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;
};
}
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;
};
}
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 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/;
# 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/;
# 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/;
# 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/;
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’;
};
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’;
};
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’;
};
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’;
};
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’;
};
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’;
};
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’;
};
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’;
};