File Coverage

blib/lib/Plack/Middleware/DiePretty.pm
Criterion Covered Total %
statement 37 37 100.0
branch 3 4 75.0
condition 5 9 55.5
subroutine 11 11 100.0
pod 1 1 100.0
total 57 62 91.9


line stmt bran cond sub pod time code
1             package Plack::Middleware::DiePretty;
2 1     1   896 use parent 'Plack::Middleware';
  1         2  
  1         8  
3 1     1   62 use strict;
  1         2  
  1         33  
4 1     1   21 use warnings;
  1         2  
  1         34  
5 1     1   5 use Plack::Util::Accessor qw(template);
  1         1  
  1         10  
6 1     1   945 use Try::Tiny;
  1         1666  
  1         60  
7 1     1   2555 use Template;
  1         34306  
  1         31  
8 1     1   903 use Path::Class;
  1         78898  
  1         84  
9 1     1   9 use FindBin qw($Bin);
  1         3  
  1         341  
10              
11             our $VERSION = '0.001';
12             $VERSION = eval $VERSION;
13              
14             sub call {
15 3     3 1 221022 my ($self, $env) = @_;
16              
17 3     2   22 local $SIG{__DIE__} = sub { die @_; };
  2         46  
18              
19 3         7 my $caught;
20 3     3   19 my $res = try { $self->app->($env); } catch { $caught = $_; [ 500, [ 'Content-Type' => 'text/plain; charset=utf-8' ], [ $caught ] ]; };
  3         94  
  2         20  
  2         12  
21              
22 3   66     119 my $template = file( $self->template || "$Bin/html/error.html" );
23              
24 3 100 33     561 if ($caught || (ref $res eq 'ARRAY' && $res->[0] == 500)) {
      66        
25 2 50       11 Template->new({ INCLUDE_PATH => $template->dir->absolute })->process($template->basename, { caught => $caught }, \(my $html)) || die $@;
26 2         139028 $res = [ 500, [ 'Content-Type' => 'text/html'], [ $html ] ];
27             }
28 3         242 $res;
29             }
30              
31             1;
32              
33             __END__