File Coverage

blib/lib/Data/ObjectStore/Cache.pm
Criterion Covered Total %
statement 29 29 100.0
branch 6 6 100.0
condition n/a
subroutine 7 7 100.0
pod 0 5 0.0
total 42 47 89.3


line stmt bran cond sub pod time code
1             package Data::ObjectStore::Cache;
2              
3 2     2   11 use strict;
  2         3  
  2         47  
4 2     2   7 use warnings;
  2         4  
  2         470  
5              
6             sub new {
7 21     21 0 912 my( $cls, $size ) = @_;
8 21         88 return bless [ $size, {}, {} ], $cls;
9             }
10              
11             sub empty {
12 1     1 0 2 my $self = shift;
13 1         3 $self->[1] = {};
14 1         3 $self->[2] = {};
15             }
16              
17             sub fetch {
18 7     7 0 1964 my( $self, $key ) = @_;
19 7         13 my( $size, $c1, $c2 ) = @$self;
20 7         11 my $v = $c1->{$key};
21 7 100       14 unless( $v ) {
22 6         11 $v = $c2->{$key};
23 6 100       11 if( $v ) {
24 4         24 $self->stow( $key, $v );
25             }
26             }
27 7         26 return $v;
28             }
29              
30             sub stow {
31 552     552 0 1026 my( $self, $key, $val ) = @_;
32 552         965 my( $size, $c1, $c2 ) = @$self;
33 552         1357 $c1->{$key} = $val;
34 552 100       1696 if( scalar( keys( %$c1 ) ) > $size ) {
35 3         5 $self->[1] = {};
36 3         8 $self->[2] = $c1;
37             }
38             }
39              
40             sub entries {
41 2     2 0 291 my $self = shift;
42 2         5 my( $size, $c1, $c2 ) = @$self;
43 2         8 my( %e ) = ( %$c1, %$c2 );
44 2         9 return keys %e;
45             }
46              
47              
48             1;