DataFile |
![]() |
DataFile - master class for managing data files
Shane P. McCarron <shane@aptest.com>
Copyright 2001-2006 Applied Testing and Technology, Inc. All Rights Reserved.
use DataFile;
# create a new DataFile object
my $file = new DataFile(path, readwrite, timeout);
# update an object
$status = $file->save();
# release the object, unlocking it
$status = $file->release();
The DataFile class is a template class that manages accessing files composed of arbitrary data. The files can be in either serialized object format or in DBM file format. The methods in this class are expected to be extended in sub-classes that manage the data in the "data" attribute, and also manage any specialized attributes outside of the "data" attribute.
The data structure of this object is optimized to be most efficient when used in conjunction with MLDBM and a single key hashed database. This object CAN use serialized objects as well, but it is MUCH slower. Note that when using MLDBM, the save method doesn't do anything (except possibly for the first time it is called if the database had not yet been converted to MLDBM format).
$file = new DataFile(path, readWrite, timeout);
Creates a new DataFile object:
returns a reference to the DataFile object.
$file->release();
This method undefines the data structures associated with the session and releases the lock on the session.
Returns 1 if we are actively Locked, 0 if not. Only meaningful under MLDBM::Sync.
Lock uses the class' writeable flag to determine whether a read or a write lock is needed.
NOTE - this should really set some sort of timeout and alarm handler thingy to get ensure we don't block forever... but in theory that can't happen.
Returns 1 on success, 0 on failure.
Returns 1 on success, 0 on failure.
Returns the path to the object.
$file->save();
returns undef if the save failed. Returns the path saved into if the save succeeded.
$file->cache(size) ;
size is the number of bytes to set aside as a cache.
Sets up a database cache for items so that they are automatically kept resident to speed access on subsequent calls.
Returns nothing.
$file->dirtyFlag();
$file->dirtyFlag(true|false);
Calling this method with no arguments will return whether or not any data has changed since the ojbect was originally created.
When ever you DO change part of the object (most notably "data") you should call this method with the true value.
$lock = $file->_flock($path, $readWrite, $timeout);
path is the path to lock.
readWrite is a boolean indicating whether the lock should be shared (a read lock), or exclusive (a write lock). Default is readOnly.
timeout is a timeout to try for the lock in seconds (default is 60).
Copyright © 2000-2006 Applied Testing and Technology, Inc. All rights reserved.