File Coverage

blib/lib/Starch/Plugin/RenewExpiration/State.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Starch::Plugin::RenewExpiration::State;
2             our $VERSION = '0.14';
3              
4 1     1   464 use Moo::Role;
  1         3  
  1         6  
5 1     1   321 use strictures 2;
  1         6  
  1         35  
6 1     1   205 use namespace::clean;
  1         3  
  1         5  
7              
8             with 'Starch::Plugin::ForState';
9              
10             around save => sub{
11             my $orig = shift;
12             my $self = shift;
13              
14             my $manager = $self->manager();
15             my $thresh = $manager->renew_threshold();
16              
17             my $variance = $manager->renew_variance();
18             if ($variance > 0) {
19             my $delta = int($thresh * $variance);
20             $thresh = ($thresh - $delta) + int( rand($delta+1) );
21             }
22              
23             $self->mark_dirty() if $self->modified() + $thresh <= time();
24              
25             return $self->$orig( @_ );
26             };
27              
28             1;