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