| 1 | ###################################################################### | ||||||||||||||||||||||||||||
| 2 | # $Id: CacheUtils.pm,v 1.39 2003/04/15 14:46:19 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::CacheUtils; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use vars qw( @ISA @EXPORT_OK ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Cache::Cache; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Storable qw( nfreeze thaw dclone ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | @ISA = qw( Exporter ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | @EXPORT_OK = qw( Assert_Defined | |||||||||||||||||||||||||||
| 24 | Build_Path | ||||||||||||||||||||||||||||
| 25 | Clone_Data | ||||||||||||||||||||||||||||
| 26 | Freeze_Data | ||||||||||||||||||||||||||||
| 27 | Static_Params | ||||||||||||||||||||||||||||
| 28 | Thaw_Data ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # throw an Exception if the Assertion fails | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub Assert_Defined | ||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 10752 | ▶ | if ( not defined $_[0] ) | ||||||||||||||||||||||||||
|
Subroutine
Assert_Defined: called CC=2 SCAR=10.5
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | my ( $package, $filename, $line ) = caller( ); | |||||||||||||||||||||||||||
| 37 | 0 | throw Error::Simple( "Assert_Defined failed: $package line $line\n" ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # Take a list of directory components and create a valid path | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub Build_Path | ||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 1138 | ▶ | my ( @p_elements ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
Build_Path: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # TODO: add this to Untaint_Path or something | ||||||||||||||||||||||||||||
| 49 | # ( $p_unique_key !~ m|[0-9][a-f][A-F]| ) or | ||||||||||||||||||||||||||||
| 50 | # throw Error::Simple( "key '$p_unique_key' contains illegal characters'" ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1138 | ▶ | if ( grep ( /\.\./, @p_elements ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 0 | throw Error::Simple( "Illegal path characters '..'" ); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1138 | return File::Spec->catfile( @p_elements ); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # use Storable to clone an object | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub Clone_Data | ||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 302 | ▶ | my ( $p_object ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
Clone_Data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 302 | ▶ | return defined $p_object ? dclone( $p_object ) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # use Storable to freeze an object | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub Freeze_Data | ||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 90 | ▶ | my ( $p_object ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
Freeze_Data: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 90 | ▶ | return defined $p_object ? nfreeze( $p_object ) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Take a parameter list and automatically shift it such that if | ||||||||||||||||||||||||||||
| 82 | # the method was called as a static method, then $self will be | ||||||||||||||||||||||||||||
| 83 | # undefined. This allows the use to write | ||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||
| 85 | # sub Static_Method | ||||||||||||||||||||||||||||
| 86 | # { | ||||||||||||||||||||||||||||
| 87 | # my ( $parameter ) = Static_Params( @_ ); | ||||||||||||||||||||||||||||
| 88 | # } | ||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||
| 90 | # and not worry about whether it is called as: | ||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||
| 92 | # Class->Static_Method( $param ); | ||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||
| 94 | # or | ||||||||||||||||||||||||||||
| 95 | # | ||||||||||||||||||||||||||||
| 96 | # Class::Static_Method( $param ); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub Static_Params | ||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 191 | ▶ | my $type = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
Static_Params: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 191 | ▶ | if ( $type and ( $type !~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type and not $type =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
MC/DC50%1/2
$type and not $type =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
$type
not $type =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
Truth table66%2/3
A and not(B)
A= $typeB= not $type =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 26 | shift( @_ ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 191 | return @_; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # use Storable to thaw an object | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub Thaw_Data | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 151 | ▶ | my ( $p_frozen_object ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
Thaw_Data: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 151 | ▶ | return defined $p_frozen_object ? thaw( $p_frozen_object ) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 4 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||