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