Plack::Middleware::DevFilter - filter a content for detecting environment
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]; } }, }, ], ; };
Plack::Middleware::DevFilter is the filter a content for detecting environment.
On SYNOPSIS code is an example for filtering favicon.ico.
favicon.ico
The below code is an example for filtering style.css.
style.css
When PLACK_ENV is development, value '#ffffff' becames '#ffffcc' in /style.css.
/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.
example/app.psgi
This is the optional parameter.
If this parameter set true value, filters are forcedly enabled to excute them.(default: false)
The filters parameter requires hash that contains 2 keys( match / proc ) and values. And both values should be code reference.
filters
match
proc
This option should be code reference. And let get back the type string of Imager.
Imager
Plack::Middleware::DevFilter is hosted on github <http://github.com/bayashi/Plack-Middleware-DevFilter>
Welcome your patches and issues :D
Dai Okabayashi <bayashi@cpan.org>
Plack::Middleware
This module was inspired by Plack::Middleware::DevFavicon.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install Plack::Middleware::DevFilter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::DevFilter
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::DevFilter
For more information on module installation, please visit the detailed CPAN module installation guide.