File Coverage

blib/lib/Cache/MemoryBackend.pm
Criterion Covered Total %
statement 32 36 88.8
branch 2 4 50.0
condition 1 3 33.3
subroutine 12 13 92.3
pod 0 8 0.0
total 47 64 73.4


line stmt bran cond sub pod time code
1             ######################################################################
2             # $Id: MemoryBackend.pm,v 1.10 2003/01/16 18:10:16 dclinton Exp $
3             # Copyright (C) 2001-2003 DeWitt Clinton All Rights Reserved
4             #
5             # Software distributed under the License is distributed on an "AS
6             # IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or
7             # implied. See the License for the specific language governing
8             # rights and limitations under the License.
9             ######################################################################
10              
11             package Cache::MemoryBackend;
12              
13 2     2   10 use strict;
  2         4  
  2         79  
14 2     2   10 use Cache::CacheUtils qw( Clone_Data );
  2         12  
  2         1050  
15              
16              
17             my $Store_Ref = { };
18              
19              
20             sub new
21             {
22 68     68 0 116 my ( $proto ) = @_;
23 68   33     340 my $class = ref( $proto ) || $proto;
24 68         129 my $self = {};
25 68         173 $self = bless( $self, $class );
26 68         164 $self->_initialize_memory_backend( );
27 68         553 return $self;
28             }
29              
30              
31             sub delete_key
32             {
33 27     27 0 49 my ( $self, $p_namespace, $p_key ) = @_;
34              
35 27         63 delete $self->_get_store_ref( )->{ $p_namespace }{ $p_key };
36             }
37              
38              
39             sub delete_namespace
40             {
41 25     25 0 51 my ( $self, $p_namespace ) = @_;
42              
43 25         57 delete $self->_get_store_ref( )->{ $p_namespace };
44             }
45              
46              
47             sub get_keys
48             {
49 47     47 0 80 my ( $self, $p_namespace ) = @_;
50              
51 47         65 return keys %{ $self->_get_store_ref( )->{ $p_namespace } };
  47         182  
52             }
53              
54              
55             sub get_namespaces
56             {
57 36     36 0 64 my ( $self ) = @_;
58              
59 36         55 return keys %{ $self->_get_store_ref( ) };
  36         93  
60             }
61              
62              
63             sub get_size
64             {
65 119     119 0 4352 my ( $self, $p_namespace, $p_key ) = @_;
66              
67 119 50       233 if ( exists $self->_get_store_ref( )->{ $p_namespace }{ $p_key } )
68             {
69 119         583 return length $self->_get_store_ref( )->{ $p_namespace }{ $p_key };
70             }
71             else
72             {
73 0         0 return 0;
74             }
75             }
76              
77              
78             sub restore
79             {
80 122     122 0 297 my ( $self, $p_namespace, $p_key ) = @_;
81              
82 122         267 return Clone_Data( $self->_get_store_ref( )->{ $p_namespace }{ $p_key } );
83             }
84              
85              
86             sub store
87             {
88 90     90 0 426 my ( $self, $p_namespace, $p_key, $p_data ) = @_;
89              
90 90         194 $self->_get_store_ref( )->{ $p_namespace }{ $p_key } = $p_data;
91             }
92              
93              
94             sub _initialize_memory_backend
95             {
96 68     68   94 my ( $self ) = @_;
97              
98 68 50       254 if ( not defined $self->_get_store_ref( ) )
99             {
100 0         0 $self->_set_store_ref( { } );
101             }
102             }
103              
104              
105             sub _get_store_ref
106             {
107 653     653   3524 return $Store_Ref;
108             }
109              
110              
111             sub _set_store_ref
112             {
113 0     0     my ( $self, $p_store_ref ) = @_;
114              
115 0           $Store_Ref = $p_store_ref;
116             }
117              
118              
119              
120             1;
121              
122             __END__