File Coverage

blib/lib/Plack/Middleware/NeverExpire.pm
Criterion Covered Total %
statement 29 29 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 40 41 97.5


line stmt bran cond sub pod time code
1 1     1   508 use 5.008001;
  1         2  
  1         33  
2 1     1   4 use strict;
  1         1  
  1         25  
3 1     1   4 use warnings;
  1         1  
  1         45  
4              
5             package Plack::Middleware::NeverExpire;
6             $Plack::Middleware::NeverExpire::VERSION = '1.005';
7             # ABSTRACT: set expiration headers far in the future
8              
9 1     1   4 use parent 'Plack::Middleware';
  1         1  
  1         7  
10              
11 1     1   56 use Plack::Util ();
  1         4  
  1         14  
12 1     1   560 use Time::Piece ();
  1         9211  
  1         24  
13 1     1   7 use Time::Seconds ();
  1         2  
  1         131  
14              
15             sub call {
16 1     1 1 17367 my $self = shift;
17             Plack::Util::response_cb( $self->app->( shift ), sub {
18 1     1   95 my $res = shift;
19 1 50       5 return if $res->[0] != 200;
20 1         12 my $date = Time::Piece->gmtime( time + Time::Seconds::ONE_YEAR );
21 1         57 Plack::Util::header_set( $res->[1], 'Expires', $date->strftime );
22 1         166 Plack::Util::header_push( $res->[1], 'Cache-Control', 'max-age=' . Time::Seconds::ONE_YEAR . ', public' );
23 1         18 return;
24 1         10 } );
25             }
26              
27             1;
28              
29             __END__