Skip to content

Instantly share code, notes, and snippets.

@ranguard
Created January 30, 2011 09:43
Show Gist options
  • Save ranguard/802724 to your computer and use it in GitHub Desktop.
Save ranguard/802724 to your computer and use it in GitHub Desktop.
Error Document not working....
#!/usr/bin/env perl
use strict;
use warnings;
use lib qw(lib);
use Plack::App::Cascade;
use Plack::Builder;
use Plack::Middleware::Static;
use Plack::Middleware::ErrorDocument;
use Plack::App::TemplateToolkit;
my $root = '/Users/leo/svn/london-pm/LPM/root';
# Just to show you can build up layers,
my $another_app = sub {
return [ 200, [ 'Content-Type' => 'text/plain' ], ["You should not be here"] ];
};
my $tt_app = Plack::App::TemplateToolkit->new(
root => $root,
extension => '.html'
)->to_app;
my $cascade = Plack::App::Cascade->new;
$cascade->add($tt_app);
# $cascade->add($another_app);
my $app = builder {
mount '/' => $cascade;
};
# The TT app is returning a 404 and if I do not
# use a subrequest then ErrorDocument also works
# ERROR:
# Not an ARRAY reference at /Users/leo/perl5/lib/perl5/Plack/Middleware/ErrorDocument.pm line 39.
# Dumping it out I have:
# It's actually getting a code ref back ($VAR1 = sub { "DUMMY" };)
$app = Plack::Middleware::ErrorDocument->wrap(
$app,
# Does not work????
404 => "/page_not_found.html",
subrequest => 1
);
$app = Plack::Middleware::Static->wrap(
$app,
path => qr{[jpg|gif|jpeg|css|js|ico]$},
root => $root
);
builder {
$app;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment