ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Cache/CacheUtilities.pm
Revision: 1.7.2.1
Committed: Mon Feb 26 18:33:45 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: v103_with_xml
CVS Tags: forV1_1_0, v103_xml_071106, V110p2, V110p1
Changes since 1.7: +15 -26 lines
Log Message:
Ensure backwards compatibility for creating projects from XML based release.

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: CacheUtilities.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2003-10-30 11:51:58+0100
7 sashby 1.7.2.1 # Revision: $Id: CacheUtilities.pm,v 1.6.2.5 2007/02/23 16:29:25 sashby Exp $
8 sashby 1.2 #
9     # Copyright: 2003 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12 sashby 1.5
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 sashby 1.7.2.1 Functions for reading and writing of cache files. This uses Storable::store() to
31 sashby 1.5 write out Perl data structures to files. For reading, the complete data structure
32 sashby 1.7.2.1 is read from the cache file using Storable::retrieve() which returns a variable
33     containing the original object.
34 sashby 1.5
35     =head1 METHODS
36    
37     =over
38    
39     =cut
40    
41 sashby 1.2 package Cache::CacheUtilities;
42     require 5.004;
43    
44     use IO::File;
45     use English;
46     use Exporter;
47    
48 sashby 1.7.2.1 use Storable;
49    
50 sashby 1.2 @ISA=qw(Exporter);
51    
52     #
53     # Common functions for interacting with caches:
54     #
55    
56 sashby 1.5 =item C<read($cachefilename)>
57    
58     Read the cache file $cachefilename and return a Perl object.
59    
60     =cut
61    
62 sashby 1.2 sub read()
63     {
64     my ($cachefilename) = @_;
65 sashby 1.7.2.1 # Retrieve the cached object from the file:
66     $cache = eval "retrieve(\"$cachefilename\")";
67 sashby 1.2 die "Cache load error: ",$EVAL_ERROR,"\n", if ($EVAL_ERROR);
68     return $cache;
69     }
70    
71 sashby 1.6 =item C<write($cacheobject,$cachefilename)>
72 sashby 1.5
73     Dump the Perl object $cacheobject to a file $cachefilename.
74    
75     =cut
76    
77 sashby 1.2 sub write()
78     {
79     my ($cacheobject,$cachefilename) = @_;
80     use File::Copy;
81 sashby 1.7 print "[ CacheUtilities::write() ] Writing cache ",$cachefilename,"\n", if ($ENV{SCRAM_DEBUG});
82     # Move the cache file to make a backup:
83 sashby 1.2 move($cachefilename,$cachefilename.".bak") if ( -r $cachefilename);
84 sashby 1.7.2.1 # Use the store method of the Storable package to write out the object to a file:
85     eval {
86     store($cacheobject,$cachefilename);
87     };
88    
89     die "Cache write error: ",$EVAL_ERROR,"\n", if ($EVAL_ERROR);
90    
91 sashby 1.3 # Change the permissions to -rw-r--r--:
92     my $filemode = 0644;
93     chmod $filemode, $cachefilename;
94    
95 sashby 1.2 return;
96     }
97    
98     1;
99 sashby 1.5
100    
101     =back
102    
103     =head1 AUTHOR/MAINTAINER
104    
105     Shaun Ashby
106    
107     =cut