| 1 | package MooseX::WithCache::Backend; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | require Data::Dump; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | has cache_type => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | has can_coerce => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | has methods => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | lazy_build => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _build_cache_type {} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cache_type: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub _build_methods { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_methods: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | cache_get => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_get: called CC=4 SCAR=14.1
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | my $cache = $self->__get_cache(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | if ($self->cache_disabled || ! $cache) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$self->cache_disabled or not $cache
$self->cache_disabled or not $cache
MC/DC0%0/2
$self->cache_disabled or not $cache
$self->cache_disabled
not $cache
MC/DC50%1/2
$self->cache_disabled or not $cache
$self->cache_disabled
not $cache
Truth table33%1/3
A or not(B)
A= $self->cache_disabledB= not $cache
Truth table66%2/3
A or not(B)
A= $self->cache_disabledB= not $cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $self->cache_debug(blessed $self, "cache_get: Cache disabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | my $keygen = $self->cache_key_generator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | my $cache_key = $keygen ? $keygen->generate($key) : $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | my $cache_ret = $cache->get($cache_key); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $self->cache_debug( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | blessed $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | "cache_get:\n + status:", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | defined $cache_ret ? "[HIT]" : "[MISS]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | "\n + key =", ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $cache_key ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $keygen ? Data::Dump::dump($key) . " ($cache_key)" : $cache_key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ) : '(null)' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | return $cache_ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | cache_set => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_set: called CC=4 SCAR=14.1
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | my ($self, $key, $value, $expire) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my $cache = $self->__get_cache(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ($self->cache_disabled || ! $cache) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$self->cache_disabled or not $cache
$self->cache_disabled or not $cache
MC/DC0%0/2
$self->cache_disabled or not $cache
$self->cache_disabled
not $cache
MC/DC50%1/2
$self->cache_disabled or not $cache
$self->cache_disabled
not $cache
Truth table33%1/3
A or not(B)
A= $self->cache_disabledB= not $cache
Truth table66%2/3
A or not(B)
A= $self->cache_disabledB= not $cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $self->cache_debug(blessed $self, "cache_set: Cache disabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $keygen = $self->cache_key_generator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | my $cache_key = $keygen ? $keygen->generate($key) : $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $self->cache_debug( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | blessed $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | "cache_set:\n + key =", ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | $cache_key ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $keygen ? Data::Dump::dump($key) . " ($cache_key)" : $cache_key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ) : '(null)' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | "\n + expire =", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ($expire || '(null)'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | MooseX::WithCache::DEBUG() > 1 ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | "\n + value =", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ($value ? Data::Dump::dump($value) : '(null)'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ) : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | return $cache->set($cache_key, $value, $expire); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | cache_del => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $cache = $self->__get_cache(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($self->cache_disabled || ! $cache) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->cache_disabled or not $cache
MC/DC0%0/2
$self->cache_disabled or not $cache
$self->cache_disabled
not $cache
Truth table0%0/3
A or not(B)
A= $self->cache_disabledB= not $cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | $self->cache_debug(blessed $self, "cache_del: Cache disabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $keygen = $self->cache_key_generator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $cache_key = $keygen ? $keygen->generate($key) : $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | if (MooseX::WithCache::DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | $self->cache_debug( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | blessed $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | "cache_del:\n + key =", ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | $cache_key ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $keygen ? Data::Dump::dump($key) . " ($cache_key)" : $cache_key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ) : '(null)' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $cache->delete($cache_key); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||