ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Cache/CacheUtilities.pm
(Generate patch)

Comparing COMP/SCRAM/src/Cache/CacheUtilities.pm (file contents):
Revision 1.1 by sashby, Fri Feb 27 16:08:16 2004 UTC vs.
Revision 1.2 by sashby, Fri Dec 10 13:41:39 2004 UTC

# Line 0 | Line 1
1 + #____________________________________________________________________
2 + # File: CacheUtilities.pm
3 + #____________________________________________________________________
4 + #  
5 + # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 + # Update: 2003-10-30 11:51:58+0100
7 + # Revision: $Id$
8 + #
9 + # Copyright: 2003 (C) Shaun Ashby
10 + #
11 + #--------------------------------------------------------------------
12 + package Cache::CacheUtilities;
13 + require 5.004;
14 +
15 + use IO::File;
16 + use English;
17 + use Exporter;
18 +
19 + @ISA=qw(Exporter);
20 +
21 + #
22 + # Common functions for interacting with caches:
23 + #
24 +
25 + sub read()
26 +   {
27 +   my ($cachefilename) = @_;
28 +   my $cachefh = IO::File->new($cachefilename, O_RDONLY)
29 +      || die "Unable to read cached data file $cachefilename: ",$ERRNO,"\n";
30 +   my @cacheitems = <$cachefh>;
31 +   close $cachefh;
32 +
33 +   # Copy the new cache object to self and return:
34 +   $cache = eval "@cacheitems";
35 +   die "Cache load error: ",$EVAL_ERROR,"\n", if ($EVAL_ERROR);
36 +   return $cache;
37 +   }
38 +
39 + sub write()
40 +   {
41 +   my ($cacheobject,$cachefilename) = @_;
42 +
43 +   use Data::Dumper;
44 +   use File::Copy;
45 +
46 +   # Rename the cache file to make a backup copy:
47 +   move($cachefilename,$cachefilename.".bak") if ( -r $cachefilename);  
48 +   # Dump the cache to file:
49 +   my $cachefh = IO::File->new($cachefilename, O_WRONLY|O_CREAT)
50 +      or die "Couldn't write to $cachefilename: ",$ERRNO,"\n";
51 +
52 +   # Name that should replace "VAR1" in the dumped
53 +   # representation of the cache object:
54 +   $Data::Dumper::Varname='cache';
55 +   $Data::Dumper::Purity = 1;
56 +   print $cachefh Dumper($cacheobject);
57 +   close $cachefh;
58 +
59 +   return;
60 +   }
61 +
62 + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines