File Coverage

blib/lib/Mojolicious/Plugin/StaticCache.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition 8 10 80.0
subroutine 3 3 100.0
pod 1 1 100.0
total 27 29 93.1


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::StaticCache;
2 1     1   447 use Mojo::Base 'Mojolicious::Plugin';
  1         3  
  1         6  
3              
4             our $VERSION = '0.02';
5              
6             sub register {
7 5     5 1 14396 my ($self, $app, $conf) = @_;
8              
9 5   100     21 $conf->{even_in_dev} ||= 0;
10 5   100     27 $conf->{max_age} ||= 2592000;
11 5   66     23 $conf->{cache_control} ||= "max-age=$conf->{max_age}, must-revalidate";
12 5         19 my $mode = $app->mode;
13 5         34 my $edev = $conf->{even_in_dev};
14              
15             $app->hook(after_static => sub {
16 15     15   21338 my $c = shift;
17 15 100 66     57 if ($mode ne 'development' || $edev) {
18 10         18 $c->res->headers->cache_control($conf->{cache_control});
19             }
20 5         32 });
21             }
22              
23             1;
24             __END__