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