blib/lib/AnyEvent/InMemoryCache.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 100% 6 / 6 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 93.3% 14 / 15 Podpod 100% 5 / 5 totaltotal 94.0% 79 / 84 CC 6 SCAR 5.0
CC
6
Cov
95%
set
3.0
get
2.1
new
2.0
CRAP 1.7
↑ Summary
1 package AnyEvent::InMemoryCache;
2 4 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = "0.01";
7  
8 4 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Time::Duration::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 3 my $class = shift;
13 3 my %args = @_;
14 3 ▶ if ( exists $args{expires_in} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'expires_in'}) { } 2 1 3
15 2 $args{expires_in} = parse_duration($args{expires_in});
16 } else {
17 1 $args{expires_in} = -1; # endless
18 }
19 3 $args{_datastore} = {};
20 3 bless \%args, $class;
21 }
22  
23 11 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
24 11 my ($self, $key, $val, $expires_in) = @_;
25 11 ▶ if ( @_ < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 4) { } 6 5 11
26 6 $expires_in = $self->{expires_in};
27 } else {
28 5 $expires_in = parse_duration($expires_in);
29 }
30 $self->{_datastore}{$key} = [
31 $val,
32 7 ▶ ($expires_in < 0 ? undef : AE::timer $expires_in, 0, sub{ delete $self->{_datastore}{$key} })
Subroutine __ANON__: called CC=1 SCAR=0.0
33 11 ▶ ];
Branch: 1 branch
BranchTrueFalseTotal
$expires_in < 0 ? : 1 10 11
34 11 $val;
35 }
36  
37 23 ▶sub get {
Subroutine get: called CC=2 SCAR=7.2
Pod documented
38 23 my ($self, $key) = @_;
39 23 ▶ ($self->{_datastore}{$key} || [])->[0];
Condition50%1/2
$self->{'_datastore'}{$key} || []
l!l
230
MC/DC0%0/1
$self->{'_datastore'}{$key} || []
$self->{'_datastore'}{$key}
Truth table50%1/2
A
A= $self->{'_datastore'}{$key}
Aresult
11
00
40 }
41  
42 44 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
43 44 my ($self, $key) = @_;
44 44 exists $self->{_datastore}{$key};
45 }
46  
47 3 ▶sub delete {
Subroutine delete: called CC=2 SCAR=6.9
Pod documented
48 3 my ($self, $key) = @_;
49 3 ▶ (delete $self->{_datastore}{$key} || [])->[0];
Condition100%2/2
delete $self->{'_datastore'}{$key} || []
l!l
21
MC/DC100%1/1
delete $self->{'_datastore'}{$key} || []
delete $self->{'_datastore'}{$key}
Truth table100%2/2
A
A= delete $self->{'_datastore'}{$key}
Aresult
11
00
50 }
51  
52  
53 # Tie-hash subroutines
54  
55 4 *TIEHASH = \&new;
56 4 *FETCH = \&get;
57 4 *STORE = \&set;
58 4 *DELETE = \&delete;
59 4 *EXISTS = \&exists;
60  
61 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
62 0 %{$_[0]->{_datastore}} = ();
63 };
64  
65 13 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
66 13 my $self = shift;
67 13 keys %{$self->{_datastore}}; # rest iterator
68 13 scalar each %{$self->{_datastore}};
69 }
70  
71 18 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
72 18 scalar each %{$_[0]->{_datastore}};
73 }
74  
75 9 ▶sub SCALAR {
Subroutine SCALAR: called CC=1 SCAR=0.0
76 9 scalar %{$_[0]->{_datastore}};
77 }
78  
79  
80 4 1;
81 __END__
↑ Summary