|
PTools::SDF::File - Abstract base class for "Simple Data File" modules |
PTools::SDF::File - Abstract base class for ``Simple Data File'' modules
This document describes version 0.08, released Nov 12, 2002.
This class is intended for use by module designers when creating a new subclass to handle another type of ``simple data file.''
package NewFileType;
use vars qw( $VERSION @ISA );
$VERSION = '0.01';
@ISA = qw( PTools::SDF::File );
use PTools::SDF::File;
# After creating this inheritance structure, the designer must
# implement all of the required abstract methods in the parent
# class, including the following.
sub new { }
sub param { }
sub ctrl { }
sub delete { }
sub ctrlDelete { }
sub save { }
sub sort { }
sub setError { }
sub dump { }
PTools::SDF::File is used to provide a foundation for various classes that provide interfaces to ``simple'' data file types.
Some of these subclasses violate the Liskov Substitution Principle. The param method will take different parameters depending on the subclass. This is simply due to differences in the format of the data records in various file types. However, all attempts should be made to keep as many of the methods as similar as possible across the subclasses.
Modules currently exist to implement various ``Simple Data Files'' including a ``Self Defining File'' format, Windows ``.INI'' files, ``tagged'' data files, and others. See the PTools::SDF::Overview manpage for details.
This method should include the option to load a data file upon instantiation or simply return an empty object.
The following methods are expected to exist in each subclass, and are expected to work in a similar manner to existing subclasses. Refer to the following notes for implementation guidelines.
See documentation on the existing subclass modules for implementation examples including the PTools::SDF::INI manpage, the PTools::SDF::SDF manpage and the PTools::SDF::TAG manpage.
Example:
# Specify a new file name for the current PTools::SDF::Subclass object
$sdfObj->ctrl( "fileName", '/tmp/newDataFilename' );
# Obtain the file name for the current PTools::SDF::Subclass object
$fileName = $sdfObj->ctrl( "fileName" );
Example:
$sdfObj->ctrlDelete('readOnly');
The implementation is left up to the module designer.
Example:
$sdfObj->save( undef, "newfilename" );
Currently, only the PTools::SDF::SDF subclass support a sort method. The options used for sorting depend entirely on which sort module is loaded at the time of the call. There are several sort modules available. See the PTools::SDF::SDF manpage for further details.
Examples:
$sdfObj->setError(0,""); # restore object to a "no error" state
$sdfObj->setError(-1, "Edit failed for field '$field' in record '$idx'");
The implementation is left up to the module designer.
Examples:
print $sdfObj->dump; # can produce a *lot* of output
print $sdfObj->dump( 0, -1 ) # dump only the "control field" values
print $sdfObj->dump( 10, 5 ) # dump recs 10 through 15.
The options used for locking depend entirely on which lock module is loaded at the time of the call. Currently there is one lock module available (listed in the SEE ALSO section, below).
Options used by the default the PTools::SDF::Lock::Advisory manpage module includes the following. See description of the extend method, below, on how to select other lock modules.
Example:
($stat,$err) = $sdfObj->lock;
$stat and die $err;
Note that the PTools::SDF::Lock::Advisory module is designed to work with any script as a stand-alone lock manager. However, when this module is not used via one of the PTools::SDF::Subclass modules the calling syntax changes. See the PTools::SDF::Lock::Advisory manpage for details.
Examples:
$sdfObj->isLocked or do { ... };
$sdfObj->notLocked or do { ... };
Example:
$sdfObj->unlock;
Currently a method must be explicitly created as extendible, and currently only the lock / unlock methods in this class and the PTools::SDF::SDF sort method are extendible using this mechanism.
Module designers are free to include extendible methods in their modules as appropriate. Refer to the code for examples of implementation.
method(s)
indicated in the MethodList parameter.
Examples:
$sdfObj->extend('sort', "PTools::SDF::Sort::Quick");
$sdfObj->extend( [ "lock","unlock" ], "PTools::SDF::Lock::Advisory");
Note that, in the last example above, the syntax shown using braces (``[]'') is the actual syntax used to pass an array reference to the extend method, and not an indication of ``optional'' parameters.
Any Perl module can be specified but, at a minimum, it should be able to do the following.
Example:
$sdfObj->extended( "method" ) or $sdfObj->extend( "method", "Class" );
To avoid this situation, the escapeIFS method is provided to encode any IFS character(s). Module designers can use this in the save method while writing the data file to disk.
Note that characters like colon (``:''), exclamation point (``!'') and pipe (``|'') work great as field delimiters. Characters such as asterisk (``*'') and percent (``%'') do not.
Performance Note: for large files this operation is an expensive overhead. Modules that use this method should contain a mechanism to disable this functionality when it is not necessary.
Example:
$sdfObj->writeLog( "$date: Error: $err at $line in $PACK", $logFile );
This PTools::SDF::File is an abstract base class intended for use by the various ``Simple Data File'' subclasses that implement a particular file format.
See the PTools::SDF::Overview manpage, the PTools::SDF::ARRAY manpage, the PTools::SDF::CSV manpage, the PTools::SDF::DB manpage, the PTools::SDF::DIR manpage, the PTools::SDF::DSET manpage, the PTools::SDF::IDX manpage, the PTools::SDF::INI manpage, the PTools::SDF::SDF manpage, the PTools::SDF::TAG manpage, the PTools::SDF::Lock::Advisory manpage, the PTools::SDF::Sort::Bubble manpage, the PTools::SDF::Sort::Quick manpage and the PTools::SDF::Sort::Shell manpage.
In addition, several implementation examples are available.
See the PTools::SDF::File::AutoHome manpage, the PTools::SDF::File::Mnttab manpage and the PTools::SDF::File::Passwd manpage. These are contained in the 'PTools-File-Cmd' distribution available on C
Chris Cobb, <nospamplease@ccobb.net>
Copyright (c) 1999-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
PTools::SDF::File - Abstract base class for "Simple Data File" modules |