Plack::Middleware::CustomErrorDocument - dynamically select error documents based on HTTP status code
version 0.003
# in app.psgi $app = Plack::Middleware::CustomErrorDocument->wrap( $app, # dynamic $path (set according to $env): 404 => sub { my $env = shift; ... return $path; }, # use static path 500 => 'path/to/error/doc', ); # or with Plack::Builder: builder { enable "Plack::Middleware::CustomErrorDocument", 404 => sub { ...; }; $app; }; # subrequests are possible as with Plack::Middleware::ErrorDocument # (but untested!) $app = Plack::Middleware::CustomErrorDocument->wrap( $app, 404 => sub { my $env = shift; ... return $path; }, subrequest => 1, );
Dynamically select an appropriate error document for an HTTP status error code. Pass in a subroutine coderef, which should take $env as the sole argument, and return the destination file path as a string.
$env
An example use would be to return a 'missing' image file for image requests that result in a 404 status (and a standard 404 HTML page for all others).
Plack::Middleware::ErrorDocument
Please report any bugs or feature requests through the issue tracker at https://github.com/mjemmeson/Plack-Middleware-CustomErrorDocument/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/mjemmeson/Plack-Middleware-CustomErrorDocument
git clone https://github.com/mjemmeson/Plack-Middleware-CustomErrorDocument.git
Michael Jemmeson <michael.jemmeson@gmail.com>
This software is copyright (c) 2012 by Foxtons Ltd.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::CustomErrorDocument, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::CustomErrorDocument
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::CustomErrorDocument
For more information on module installation, please visit the detailed CPAN module installation guide.