Gideon/Plugin/Cache.pm

filter: Statementstmt 46.8% 15 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 2 totaltotal 36.0% 18 / 50 CC 4 SCAR 21.9
CC
4
Cov
38%
_compute
20.0
find_one
2.0
find
2.0
CRAP 8.9
« Gideon/Plugin/StrictMode.pm ↑ Summary Gideon/Meta/Attribute/Trait/DBI/Inflate/DateTime.pm »
1 package Gideon::Plugin::Cache;
2 {
3 1 $Gideon::Plugin::Cache::VERSION = '0.0.3';
4 }
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Gideon::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #ABSTRACT: Cache Plugin
10  
11 1 extends 'Gideon::Plugin';
12  
13 1 my $serializer = JSON->new->utf8->canonical;
14  
15 0 ▶sub find_one {
Subroutine find_one: not called CC=1 SCAR=6.9
Pod undocumented
16 0 my ( $self, $target, %query ) = @_;
17 0 $self->_compute( 'find_one', $target, %query );
18 }
19  
20 0 ▶sub find {
Subroutine find: not called CC=1 SCAR=6.9
Pod undocumented
21 0 my ( $self, $target, %query ) = @_;
22 0 $self->_compute( 'find', $target, %query );
23 }
24  
25 0 ▶sub _compute {
Subroutine _compute: not called CC=4 SCAR=30.0
26 0 my ( $self, $method, $target, %query ) = @_;
27  
28 0 my $expiration = delete $query{-cache_for};
29  
30 0 ▶ if ( Gideon::Registry->has_cache and $expiration ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Gideon::Registry'->has_cache and $expiration) { } 0 0 0
Condition0%0/3
"Gideon::Registry"->has_cache and $expiration
!ll&&!rl&&r
000
MC/DC0%0/2
"Gideon::Registry"->has_cache and $expiration
"Gideon::Registry"->has_cache $expiration
Truth table0%0/3
A and B
A= "Gideon::Registry"->has_cacheB= $expiration
ABresult
0X0
100
111
31 0 my $key = $self->_serialize_key( $target, \%query );
32 0 my $cache = Gideon::Registry->get_cache;
33 0 my $rs = $cache->get($key);
34  
35 0 ▶ return $rs if $rs;
Branch: 1 branch
BranchTrueFalseTotal
if $rs 0 0 0
36  
37 0 $rs = $self->next->$method( $target, %query );
38 0 $cache->set( $key, $rs, $expiration );
39 0 return $rs;
40 }
41 else {
42 0 return $self->next->$method( $target, %query );
43 }
44 }
45  
46 0 ▶sub _serialize_key {
Subroutine _serialize_key: not called CC=1 SCAR=6.9
47 0 my ( $self, $prefix, $obj ) = @_;
48 0 return "$prefix:" . $serializer->encode($obj);
49 }
50  
51 1 __PACKAGE__->meta->make_immutable;
52 1 1;
53  
54 __END__
« Gideon/Plugin/StrictMode.pm ↑ Summary Gideon/Meta/Attribute/Trait/DBI/Inflate/DateTime.pm »