line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
4
|
|
16
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
129
|
|
14
|
4
|
|
|
4
|
|
22
|
use vars qw( @ISA @EXPORT_OK ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
148
|
|
15
|
4
|
|
|
4
|
|
28
|
use Cache::Cache; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
125
|
|
16
|
4
|
|
|
4
|
|
17
|
use Error; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
21
|
|
17
|
4
|
|
|
4
|
|
176
|
use Exporter; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
139
|
|
18
|
4
|
|
|
4
|
|
25
|
use File::Spec; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
105
|
|
19
|
4
|
|
|
4
|
|
2764
|
use Storable qw( nfreeze thaw dclone ); |
|
4
|
|
|
|
|
12348
|
|
|
4
|
|
|
|
|
2165
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
@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
|
11010
|
50
|
|
11010
|
0
|
24412
|
if ( not defined $_[0] ) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
0
|
my ( $package, $filename, $line ) = caller( ); |
37
|
0
|
|
|
|
|
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
|
1165
|
|
|
1165
|
0
|
2398
|
my ( @p_elements ) = @_; |
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
|
1165
|
50
|
|
|
|
4644
|
if ( grep ( /\.\./, @p_elements ) ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
0
|
throw Error::Simple( "Illegal path characters '..'" ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1165
|
|
|
|
|
18687
|
return File::Spec->catfile( @p_elements ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# use Storable to clone an object |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub Clone_Data |
64
|
|
|
|
|
|
|
{ |
65
|
304
|
|
|
304
|
0
|
366
|
my ( $p_object ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
304
|
100
|
|
|
|
15440
|
return defined $p_object ? dclone( $p_object ) : undef; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# use Storable to freeze an object |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub Freeze_Data |
74
|
|
|
|
|
|
|
{ |
75
|
92
|
|
|
92
|
0
|
135
|
my ( $p_object ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
92
|
50
|
|
|
|
417
|
return defined $p_object ? nfreeze( $p_object ) : undef; |
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
|
193
|
|
|
193
|
0
|
290
|
my $type = ref $_[0]; |
102
|
|
|
|
|
|
|
|
103
|
193
|
100
|
66
|
|
|
624
|
if ( $type and ( $type !~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ ) ) |
104
|
|
|
|
|
|
|
{ |
105
|
26
|
|
|
|
|
47
|
shift( @_ ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
193
|
|
|
|
|
386
|
return @_; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# use Storable to thaw an object |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub Thaw_Data |
115
|
|
|
|
|
|
|
{ |
116
|
153
|
|
|
153
|
0
|
224
|
my ( $p_frozen_object ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
153
|
50
|
|
|
|
651
|
return defined $p_frozen_object ? thaw( $p_frozen_object ) : undef; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |