File Coverage

blib/lib/Plack/Middleware/SimpleContentFilter.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 6 66.6
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             package Plack::Middleware::SimpleContentFilter;
2 1     1   6 use strict;
  1         2  
  1         27  
3 1     1   3 use warnings;
  1         13  
  1         41  
4 1     1   4 use parent qw( Plack::Middleware );
  1         1  
  1         4  
5              
6 1     1   44 use Plack::Util;
  1         2  
  1         16  
7 1     1   3 use Plack::Util::Accessor qw( filter );
  1         1  
  1         15  
8              
9             sub call {
10 1     1 1 2 my $self = shift;
11              
12 1         13 my $res = $self->app->(@_);
13             $self->response_cb($res, sub {
14 1     1   1 my $res = shift;
15 1         6 my $h = Plack::Util::headers($res->[1]);
16 1 50       10 return unless $h->get('Content-Type');
17 1 50       6 if ($h->get('Content-Type') =~ m!^text/!) {
18             return sub {
19 3         4 my $chunk = shift;
20 3 100       7 return unless defined $chunk;
21 2         3 local $_ = $chunk;
22 2         5 $self->filter->();
23 2         11 return $_;
24 1         16 };
25             }
26 1         67 });
27             }
28              
29             1;
30              
31             __END__