| 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
Condition0%0/3
"Gideon::Registry"->has_cache and $expiration
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||