Skip to content

Instantly share code, notes, and snippets.

@abh
Created October 4, 2010 05:31
Show Gist options
  • Save abh/609276 to your computer and use it in GitHub Desktop.
Save abh/609276 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use local::lib;
use lib '/Users/ask/src/Plack/lib';
use Plack;
use Plack::Builder;
use HTTP::Exception;
builder {
enable "ErrorDocument",
404 => '/error/404',
500 => '/error/500',
subrequest => 1;
enable 'HTTPExceptions';
sub {
my $env = shift;
warn "Fetching: $env->{PATH_INFO}\n";
if ($env->{PATH_INFO} =~ m!^/error/(\d+)!) {
return [ 200, [], ["Error: $1"] ]
}
if ($env->{PATH_INFO} =~ m!^/test!) {
return [ 404, [], ["Test 404"] ]
}
HTTP::Exception->throw(404);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment