File Coverage

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


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::StaticCache;
2 1     1   532 use Mojo::Base 'Mojolicious::Plugin';
  1         2  
  1         6  
3              
4             our $VERSION = '0.01';
5              
6             sub register {
7 5     5 1 16209 my ($self, $app, $conf) = @_;
8              
9 5   100     25 $conf->{even_in_dev} ||= 0;
10 5   100     25 $conf->{max_age} ||= 2592000;
11 5   66     28 $conf->{cache_control} ||= "max-age=$conf->{max_age}, must-revalidate";
12              
13             $app->hook(after_static => sub {
14 15     15   27187 my $c = shift;
15 15 100 66     43 if ($app->mode eq 'production' || $conf->{even_in_dev}) {
16 10         86 $c->res->headers->cache_control($conf->{cache_control});
17             }
18 5         38 });
19             }
20              
21             1;
22             __END__