File Coverage

blib/lib/Mojolicious/Plugin/Prometheus/Guard.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Prometheus::Guard;
2 12     12   91 use Mojo::Base -base, -signatures;
  12         29  
  12         142  
3              
4 12     12   4872 use Fcntl ':flock';
  12         39  
  12         2141  
5 12     12   6698 use Sereal qw(get_sereal_decoder get_sereal_encoder);
  12         16954  
  12         4420  
6              
7             has 'share';
8              
9 13     13   5182 sub _change($self, $cb) {
  13         58  
  13         110  
  13         60  
10 13         93 $self->share->lock(LOCK_EX);
11              
12 13         509 my $stats = $self->_fetch;
13 13         354 $cb->($_) for $stats;
14 13         179636 $self->_store($stats);
15              
16 13         1602 $self->share->unlock;
17             }
18              
19 39     39   228 sub _fetch($self) {
  39         88  
  39         56  
20 39 100       140 return {} unless my $data = $self->share->fetch;
21 29         983 return get_sereal_decoder->decode($data);
22             }
23              
24 13     13   37 sub _store($self, $value) {
  13         33  
  13         27  
  13         32  
25 13         84 $self->share->store(get_sereal_encoder->encode($value));
26             }
27              
28             1;