Skip to content

Instantly share code, notes, and snippets.

@hdp
Created August 20, 2010 17:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hdp/540793 to your computer and use it in GitHub Desktop.
Save hdp/540793 to your computer and use it in GitHub Desktop.
# vim: ft=perl:
use strict;
use warnings;
use Plack::Builder;
use Plack::App::WrapCGI;
use Plack::App::URLMap;
builder {
enable 'Static',
path => qr{^/(images|skins|js)/},
root => './';
my $map = Plack::App::URLMap->new;
my @mount;
for my $cgi (<*.cgi>) {
my $app = eval { Plack::App::WrapCGI->new(script => $cgi)->to_app };
unless ($app) {
warn $@;
next;
}
my $wrapped = sub {
$Bugzilla::_request_cache = {};
Bugzilla::init_page();
my $res = $app->(@_);
Bugzilla::_cleanup();
return $res;
};
push @mount, [ '/' => $wrapped ] if $cgi eq 'index.cgi';
push @mount, [ "/$cgi" => $wrapped ];
}
$map->mount(@$_) for @mount;
$map->to_app;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment