NAME
Plack::Middleware::DevFilter - filter a content for detecting environment
SYNOPSIS
use Plack::Builder;
builder {
enable 'DevFilter',
filters => [
{ # favicon.ico
match => sub {
my ($self, $env, $res) = @_;
return 1 if $env->{PATH_INFO} eq '/favicon.ico';
},
proc => sub {
my ($self, $env, $res,
$body_ref, $imager, $image_type) = @_;
if ($imager) {
$imager = $imager->convert(preset => 'gray')
or die Imager->errstr;
my $out;
$imager->write(data => \$out, type => $image_type);
$res->[2] = [$out];
}
},
},
],
;
};
DESCRIPTION
Plack::Middleware::DevFilter is the filter a content for detecting environment.
On SYNOPSIS code is an example for filtering favicon.ico
.
The below code is an example for filtering style.css
.
When PLACK_ENV is development, value '#ffffff' becames '#ffffcc' in /style.css
.
use Plack::Builder;
builder {
enable 'DevFilter',
filters => [
{
match => sub {
my ($self, $env, $res) = @_;
return 1 if $env->{PATH_INFO} eq '/style.css';
},
proc => sub {
my ($self, $env, $res,
$body_ref, $imager, $image_type) = @_;
$$body_ref =~ s/#ffffff/#ffffcc/g;
$res->[2] = [$$body_ref];
},
},
],
;
};
See also: example/app.psgi
dir.
OPTION PARAMETERS
- force_enable
-
This is the optional parameter.
If this parameter set true value, filters are forcedly enabled to excute them.(default: false)
- filters
-
The
filters
parameter requires hash that contains 2 keys(match
/proc
) and values. And both values should be code reference. - image_type
-
This is the optional parameter.
This option should be code reference. And let get back the type string of
Imager
.
METHODS
- prepare_app
- call
REPOSITORY
Plack::Middleware::DevFilter is hosted on github <http://github.com/bayashi/Plack-Middleware-DevFilter>
Welcome your patches and issues :D
AUTHOR
Dai Okabayashi <bayashi@cpan.org>
SEE ALSO
This module was inspired by Plack::Middleware::DevFavicon.
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.