EntityModel/Cache/Perl.pm

filter: Statementstmt 46.1% 18 / 39 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 83.3% 5 / 6 totaltotal 47.3% 27 / 57 CC 3 SCAR 15.3
CC
3
Cov
42%
atomic
12.0
remove
2.0
incr
2.0
CRAP 4.6
« EntityModel/Test/Cache.pm ↑ Summary EntityModel/Collection.pm »
1 package EntityModel::Cache::Perl;
2 {
3 2 $EntityModel::Cache::Perl::VERSION = '0.102';
4 }
5 2 ▶use EntityModel::Class {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 _isa => [qw(EntityModel::Cache)],
7 2 };
8  
9 =head1 NAME
10  
11 EntityModel::Cache::Perl - simple proof-of-concept Perl-level caching layer
12  
13 =head1 VERSION
14  
15 version 0.102
16  
17 =head1 SYNOPSIS
18  
19 =head1 DESCRIPTION
20  
21 =cut
22  
23 2 ▶use Tie::Cache::LRU;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 our %cache;
26 2 tie %cache, 'Tie::Cache::LRU', 1024;
27  
28 =head1 METHODS
29  
30 =cut
31  
32 5 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
33 5 my $self = shift;
34 5 my $k = shift;
35 5 return $cache{$k};
36 }
37  
38 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
39 0 my $self = shift;
40 0 my $k = shift;
41 0 delete $cache{$k};
42 0 return $self;
43 }
44  
45 0 ▶sub incr {
Subroutine incr: not called CC=1 SCAR=6.9
Pod documented
46 0 my $self = shift;
47 0 my $k = shift;
48 0 ++$cache{$k};
49 }
50  
51 0 ▶sub decr {
Subroutine decr: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my $self = shift;
53 0 my $k = shift;
54 0 --$cache{$k};
55 }
56  
57 5 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
58 5 my $self = shift;
59 5 my $k = shift;
60 5 $cache{$k} = shift;
61 5 return $self;
62 }
63  
64 0 ▶sub atomic {
Subroutine atomic: not called CC=3 SCAR=24.8
Pod documented
65 0 my $self = shift;
66 0 ▶ die 'This is an instance method' unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
67 0 my $k = shift;
68 0 my $f = shift;
69 0 my $v = $self->get($k);
70  
71 0 ▶ if($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
72 0 logDebug('[%s] is cached, %d bytes', $k, length($v));
73 0 return $v;
74 }
75  
76 0 $v = $f->($k); # old memcached without cas support may die here
77 0 $self->set($k, $v, 5);
78 0 return $v;
79 }
80  
81 2 1;
82  
83 __END__
« EntityModel/Test/Cache.pm ↑ Summary EntityModel/Collection.pm »