/usr/share/perl5/Plack/Middleware/SimpleContentFilter.pm is in libplack-perl 0.9985-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | package Plack::Middleware::SimpleContentFilter;
use strict;
use warnings;
use parent qw( Plack::Middleware );
use Plack::Util;
use Plack::Util::Accessor qw( filter );
sub call {
my $self = shift;
my $res = $self->app->(@_);
$self->response_cb($res, sub {
my $res = shift;
my $h = Plack::Util::headers($res->[1]);
if ($h->get('Content-Type') =~ m!^text/!) {
return sub {
my $chunk = shift;
return unless defined $chunk;
local $_ = $chunk;
$self->filter->();
return $_;
};
}
});
}
1;
__END__
=head1 NAME
Plack::Middleware::SimpleContentFilter - Filters response content
=head1 SYNOPSIS
use Plack::Builder;
my $app = sub {
return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
};
builder {
enable "Plack::Middleware::SimpleContentFilter",
filter => sub { s/Foo/Bar/g; };
$app;
};
=head1 DESCRIPTION
B<This middleware should be considered as a demo. Running this against
your application might break your HTML unless you code the filter
callback carefully>.
Plack::Middleware::SimpleContentFilter is a simple content text filter
to run against response body. This middleware is only enabled against
responses with C<text/*> Content-Type.
=head1 AUTHOR
Tatsuhiko Miyagawa
=cut
|