File Coverage

blib/lib/Plack/ResponseHelper/Text.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition 2 4 50.0
subroutine 6 6 100.0
pod 0 1 0.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package Plack::ResponseHelper::Text;
2 1     1   5 use strict;
  1         11  
  1         36  
3 1     1   5 use warnings;
  1         2  
  1         27  
4              
5 1     1   5 use Encode qw/encode/;
  1         1  
  1         94  
6 1     1   836 use Plack::Response;
  1         16976  
  1         156  
7              
8             sub helper {
9 1     1 0 3 my $init = shift;
10 1   50     11 my $content_type = $init && $init->{content_type} || 'text/plain';
11 1   50     16 my $encoding = $init && $init->{encoding} || 'utf-8';
12              
13             return sub {
14 2     2   5 my $r = shift;
15 2         21 my $response = Plack::Response->new(200);
16 2         56 $response->content_type($content_type);
17 2 100       81 $response->body(ref $r eq 'ARRAY' ? [map {encode $encoding, $_} @$r] : encode $encoding, $r);
  3         80  
18 2         195 return $response;
19 1         10 };
20             }
21              
22             1;
23              
24             __END__