Skip to content

Instantly share code, notes, and snippets.

@gugod
Created October 17, 2009 15:49
Show Gist options
  • Select an option

  • Save gugod/212377 to your computer and use it in GitHub Desktop.

Select an option

Save gugod/212377 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use UNIVERSAL::require;
use HTTP::Message;
use YAML;
use CGI::PSGI;
BEGIN {
Jifty::Util->require or die $UNIVERSAL::require::ERROR;
# XXX: Anyway to figure this out automatically ?
my $root = $ENV{JIFTY_APP_ROOT} = "/Users/gugod/src/Pony";
unshift @INC, "$root/lib";
}
use Jifty;
chdir($ENV{'JIFTY_APP_ROOT'});
Jifty->new;
sub app {
my $env = shift;
local *ENV = $env;
my ($status, $headers, $body);
my $out;
local *STDOUT;
open STDOUT, ">", \$out;
Jifty->handler->add_trigger(
before_cleanup => sub {
my $r = Jifty->handler->apache;
$headers = $r->headers_out;
$status = delete $headers->{Status} || '200 OK';
});
Jifty->handler->handle_request( cgi => CGI::PSGI->new($env) );
my $m = HTTP::Message->parse($out);
$body = $m->content;
close STDOUT;
return [$status, [ %$headers ], [ $body ]];
}
\&app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment