9 |
|
# Copyright: 2003 (C) Shaun Ashby |
10 |
|
# |
11 |
|
#-------------------------------------------------------------------- |
12 |
+ |
|
13 |
+ |
=head1 NAME |
14 |
+ |
|
15 |
+ |
Cache::CacheUtilities - Utilities for reading and writing of cache files. |
16 |
+ |
|
17 |
+ |
=head1 SYNOPSIS |
18 |
+ |
|
19 |
+ |
Reading: |
20 |
+ |
|
21 |
+ |
print "Reading cached data","\n",if ($ENV{SCRAM_DEBUG}); |
22 |
+ |
$cacheobject=&Cache::CacheUtilities::read($cachename); |
23 |
+ |
|
24 |
+ |
Writing: |
25 |
+ |
|
26 |
+ |
&Cache::CacheUtilities::write($cacheobject,$cachename); |
27 |
+ |
|
28 |
+ |
=head1 DESCRIPTION |
29 |
+ |
|
30 |
+ |
Functions for reading and writing of cache files. This uses Data::Dumper to |
31 |
+ |
write out Perl data structures to files. For reading, the complete data structure |
32 |
+ |
is read from the cache file and stored in a variable which is then evalled to |
33 |
+ |
restore the original object. |
34 |
+ |
|
35 |
+ |
=head1 METHODS |
36 |
+ |
|
37 |
+ |
=over |
38 |
+ |
|
39 |
+ |
=cut |
40 |
+ |
|
41 |
|
package Cache::CacheUtilities; |
42 |
|
require 5.004; |
43 |
|
|
51 |
|
# Common functions for interacting with caches: |
52 |
|
# |
53 |
|
|
54 |
+ |
=item C<read($cachefilename)> |
55 |
+ |
|
56 |
+ |
Read the cache file $cachefilename and return a Perl object. |
57 |
+ |
|
58 |
+ |
=cut |
59 |
+ |
|
60 |
|
sub read() |
61 |
|
{ |
62 |
|
my ($cachefilename) = @_; |
71 |
|
return $cache; |
72 |
|
} |
73 |
|
|
74 |
+ |
=item C<write($cacheobject,$cachefilenam)> |
75 |
+ |
|
76 |
+ |
Dump the Perl object $cacheobject to a file $cachefilename. |
77 |
+ |
|
78 |
+ |
=cut |
79 |
+ |
|
80 |
|
sub write() |
81 |
|
{ |
82 |
|
my ($cacheobject,$cachefilename) = @_; |
84 |
|
use Data::Dumper; |
85 |
|
use File::Copy; |
86 |
|
|
87 |
< |
print "[ CacheUtilities::write() ] Writing cache ",$cachefilename,"\n"; |
87 |
> |
print "[ CacheUtilities::write() ] Writing cache ",$cachefilename,"\n", if ($ENV{SCRAM_DEBUG}); |
88 |
|
|
89 |
|
# Rename the cache file to make a backup copy: |
90 |
|
move($cachefilename,$cachefilename.".bak") if ( -r $cachefilename); |
107 |
|
} |
108 |
|
|
109 |
|
1; |
110 |
+ |
|
111 |
+ |
|
112 |
+ |
=back |
113 |
+ |
|
114 |
+ |
=head1 AUTHOR/MAINTAINER |
115 |
+ |
|
116 |
+ |
Shaun Ashby |
117 |
+ |
|
118 |
+ |
=cut |