1 # This is Plack::Server::CGI, copied almost verbatim.
2 # Except I inlined the bits of Plack::Util it needed.
3 # Because it loads a number of modules that I didn't.
4 # miyagawa, I'm sorry to butcher your code like this.
5 # The apology would have been in the form of a haiku.
6 # But I needed more syllables than that would permit.
7 # So I thought perhaps I'd make it bricktext instead.
25 if (ref $body eq 'ARRAY') {
26 for my $line (@$body) {
27 $cb->($line) if length $line;
30 local $/ = \4096 unless ref $/;
31 while (defined(my $line = $body->getline)) {
32 $cb->($line) if length $line;
41 sub new { bless {}, shift }
44 my ($self, $app) = @_;
46 while (my ($k, $v) = each %ENV) {
47 next unless $k =~ qr/^(?:REQUEST_METHOD|SCRIPT_NAME|PATH_INFO|QUERY_STRING|SERVER_NAME|SERVER_PORT|SERVER_PROTOCOL|CONTENT_LENGTH|CONTENT_TYPE|REMOTE_ADDR|REQUEST_URI)$|^HTTP_/;
50 $env{'HTTP_COOKIE'} ||= $ENV{COOKIE};
51 $env{'psgi.version'} = [ 1, 0 ];
52 $env{'psgi.url_scheme'} = ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http';
53 $env{'psgi.input'} = *STDIN;
54 $env{'psgi.errors'} = *STDERR;
55 $env{'psgi.multithread'} = Plack::Util::FALSE;
56 $env{'psgi.multiprocess'} = Plack::Util::TRUE;
57 $env{'psgi.run_once'} = Plack::Util::TRUE;
58 my $res = $app->(\%env);
59 print "Status: $res->[0]\n";
60 my $headers = $res->[1];
61 while (my ($k, $v) = splice(@$headers, 0, 2)) {
67 my $cb = sub { print STDOUT $_[0] };
69 Plack::Util::foreach($body, $cb);
79 use Plack::Server::CGI;
81 # or Plack::Util::load_psgi("/path/to/app.psgi");
86 [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
91 Plack::Server::CGI->new->run($app);
95 L<Plack::Server::Base>