| 1 | ###################################################################### | ||||||||||||||||||||
| 2 | # $Id: FileCache.pm,v 1.31 2002/04/07 17:04:46 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 | |||||||||||||||||||||
| 12 | package Cache::FileCache; | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 2 | ▶ | use Cache::BaseCache; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 2 | ▶ | use Cache::Cache; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 2 | ▶ | use Cache::CacheUtils qw ( Assert_Defined Build_Path Static_Params ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 2 | ▶ | use Cache::FileBackend; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 2 | ▶ | use Cache::Object; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 2 | ▶ | use Error; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 2 | ▶ | use File::Spec::Functions; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | @ISA = qw ( Cache::BaseCache ); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # by default, the cache nests all entries on the filesystem three | ||||||||||||||||||||
| 30 | # directories deep | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | my $DEFAULT_CACHE_DEPTH = 3; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # by default, the root of the cache is located in 'FileCache'. On a | ||||||||||||||||||||
| 36 | # UNIX system, this will appear in "/tmp/FileCache/" | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | my $DEFAULT_CACHE_ROOT = "FileCache"; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # by default, the directories in the cache on the filesystem should | ||||||||||||||||||||
| 42 | # be globally writable to allow for multiple users. While this is a | ||||||||||||||||||||
| 43 | # potential security concern, the actual cache entries are written | ||||||||||||||||||||
| 44 | # with the user's umask, thus reducing the risk of cache poisoning | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 2 | my $DEFAULT_DIRECTORY_UMASK = 000; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | sub Clear | ||||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 16 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
Clear: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 16 | foreach my $namespace ( _Namespaces( $p_optional_cache_root ) ) | |||||||||||||||||||
| 54 | { | ||||||||||||||||||||
| 55 | 18 | _Get_Cache( $namespace, $p_optional_cache_root )->clear( ); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | sub Purge | ||||||||||||||||||||
| 61 | { | ||||||||||||||||||||
| 62 | 4 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
Purge: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 4 | foreach my $namespace ( _Namespaces( $p_optional_cache_root ) ) | |||||||||||||||||||
| 65 | { | ||||||||||||||||||||
| 66 | 4 | _Get_Cache( $namespace, $p_optional_cache_root )->purge( ); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub Size | ||||||||||||||||||||
| 72 | { | ||||||||||||||||||||
| 73 | 14 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
Size: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 14 | my $size = 0; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 14 | foreach my $namespace ( _Namespaces( $p_optional_cache_root ) ) | |||||||||||||||||||
| 78 | { | ||||||||||||||||||||
| 79 | 6 | $size += _Get_Cache( $namespace, $p_optional_cache_root )->size( ); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 14 | return $size; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub new | ||||||||||||||||||||
| 87 | { | ||||||||||||||||||||
| 88 | 31 | ▶ | my ( $self ) = _new( @_ ); | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 31 | $self->_complete_initialization( ); | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 31 | return $self; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | sub _Get_Backend | ||||||||||||||||||||
| 97 | { | ||||||||||||||||||||
| 98 | 34 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
_Get_Backend: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 34 | return new Cache::FileBackend( _Build_Cache_Root( $p_optional_cache_root ) ); | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | # return the OS default temp directory | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub _Get_Temp_Directory | ||||||||||||||||||||
| 108 | { | ||||||||||||||||||||
| 109 | 68 | ▶ | my $tmpdir = File::Spec->tmpdir( ) or | ||||||||||||||||||
|
Subroutine
_Get_Temp_Directory: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||
| 110 | throw Error::Simple( "No tmpdir on this system. Upgrade File::Spec?" ); | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 68 | return $tmpdir; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | sub _Build_Cache_Root | ||||||||||||||||||||
| 117 | { | ||||||||||||||||||||
| 118 | 34 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
_Build_Cache_Root: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 34 | ▶ | if ( defined $p_optional_cache_root ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | { | ||||||||||||||||||||
| 122 | 0 | return $p_optional_cache_root; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | else | ||||||||||||||||||||
| 125 | { | ||||||||||||||||||||
| 126 | 34 | return Build_Path( _Get_Temp_Directory( ), $DEFAULT_CACHE_ROOT ); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | sub _Namespaces | ||||||||||||||||||||
| 132 | { | ||||||||||||||||||||
| 133 | 34 | ▶ | my ( $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
_Namespaces: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 34 | return _Get_Backend( $p_optional_cache_root )->get_namespaces( ); | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | sub _Get_Cache | ||||||||||||||||||||
| 140 | { | ||||||||||||||||||||
| 141 | 28 | ▶ | my ( $p_namespace, $p_optional_cache_root ) = Static_Params( @_ ); | ||||||||||||||||||
|
Subroutine
_Get_Cache: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 28 | Assert_Defined( $p_namespace ); | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 28 | ▶ | if ( defined $p_optional_cache_root ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 146 | { | ||||||||||||||||||||
| 147 | 0 | return new Cache::FileCache( { 'namespace' => $p_namespace, | |||||||||||||||||||
| 148 | 'cache_root' => $p_optional_cache_root } ); | ||||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | else | ||||||||||||||||||||
| 151 | { | ||||||||||||||||||||
| 152 | 28 | return new Cache::FileCache( { 'namespace' => $p_namespace } ); | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | sub _new | ||||||||||||||||||||
| 158 | { | ||||||||||||||||||||
| 159 | 34 | ▶ | my ( $proto, $p_options_hash_ref ) = @_; | ||||||||||||||||||
|
Subroutine
_new: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 160 | 34 | ▶ | my $class = ref( $proto ) || $proto; | ||||||||||||||||||
|
Condition66%2/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 34 | my $self = $class->SUPER::_new( $p_options_hash_ref ); | |||||||||||||||||||
| 163 | 34 | $self->_initialize_file_backend( ); | |||||||||||||||||||
| 164 | 34 | return $self; | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | sub _initialize_file_backend | ||||||||||||||||||||
| 169 | { | ||||||||||||||||||||
| 170 | 34 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
_initialize_file_backend: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 34 | $self->_set_backend( new Cache::FileBackend( $self->_get_initial_root( ), | |||||||||||||||||||
| 173 | $self->_get_initial_depth( ), | ||||||||||||||||||||
| 174 | $self->_get_initial_umask( ) )); | ||||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | sub _get_initial_root | ||||||||||||||||||||
| 179 | { | ||||||||||||||||||||
| 180 | 34 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
_get_initial_root: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 34 | ▶ | if ( defined $self->_read_option( 'cache_root' ) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 183 | { | ||||||||||||||||||||
| 184 | 0 | return $self->_read_option( 'cache_root' ); | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | else | ||||||||||||||||||||
| 187 | { | ||||||||||||||||||||
| 188 | 34 | return Build_Path( _Get_Temp_Directory( ), $DEFAULT_CACHE_ROOT ); | |||||||||||||||||||
| 189 | } | ||||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | sub _get_initial_depth | ||||||||||||||||||||
| 194 | { | ||||||||||||||||||||
| 195 | 34 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
_get_initial_depth: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 34 | return $self->_read_option( 'cache_depth', $DEFAULT_CACHE_DEPTH ); | |||||||||||||||||||
| 198 | } | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | sub _get_initial_umask | ||||||||||||||||||||
| 202 | { | ||||||||||||||||||||
| 203 | 34 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
_get_initial_umask: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | 34 | return $self->_read_option( 'directory_umask', $DEFAULT_DIRECTORY_UMASK ); | |||||||||||||||||||
| 206 | } | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | sub get_cache_depth | ||||||||||||||||||||
| 210 | { | ||||||||||||||||||||
| 211 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
get_cache_depth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | 0 | return $self->_get_backend( )->get_depth( ); | |||||||||||||||||||
| 214 | } | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | sub set_cache_depth | ||||||||||||||||||||
| 218 | { | ||||||||||||||||||||
| 219 | 0 | ▶ | my ( $self, $p_cache_depth ) = @_; | ||||||||||||||||||
|
Subroutine
set_cache_depth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 0 | $self->_get_backend( )->set_depth( $p_cache_depth ); | |||||||||||||||||||
| 222 | } | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | sub get_cache_root | ||||||||||||||||||||
| 226 | { | ||||||||||||||||||||
| 227 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
get_cache_root: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 0 | return $self->_get_backend( )->get_root( ); | |||||||||||||||||||
| 230 | } | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | sub set_cache_root | ||||||||||||||||||||
| 234 | { | ||||||||||||||||||||
| 235 | 0 | ▶ | my ( $self, $p_cache_root ) = @_; | ||||||||||||||||||
|
Subroutine
set_cache_root: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 0 | $self->_get_backend( )->set_root( $p_cache_root ); | |||||||||||||||||||
| 238 | } | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | sub get_directory_umask | ||||||||||||||||||||
| 242 | { | ||||||||||||||||||||
| 243 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
get_directory_umask: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 0 | return $self->_get_backend( )->get_directory_umask( ); | |||||||||||||||||||
| 246 | } | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | sub set_directory_umask | ||||||||||||||||||||
| 250 | { | ||||||||||||||||||||
| 251 | 0 | ▶ | my ( $self, $p_directory_umask ) = @_; | ||||||||||||||||||
|
Subroutine
set_directory_umask: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | 0 | $self->_get_backend( )->set_directory_umask( $p_directory_umask ); | |||||||||||||||||||
| 254 | } | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 2 | 1; | |||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | __END__ | ||||||||||||||||||||