XAS::Lib::Spool - A Perl extension for the XAS environment
use XAS::System; my $spl = XAS::System->module( spool => { -spooldir => 'spool' } ); $spl->packet("This is some data"); $spl->write(); $spl->clear(); $spl->packet("This is some other data"); $spl->write(); my @files = $spl->scan(); foreach my $file (@files) { my $packet = $spl->read($file); print $packet->{data}; $spl->delete($file); }
This module provides the basic handling of spool files. This module provides basic read, write, scan and delete functionality for those files.
This functionality is designed to be overridden with more specific methods for each type of spool file required.
Individual spool files are stored in sub directories. Since multiple processes may be accessing those directories, lock files are being used to control access. This is an important requirement to prevent possible race conditions between those processes.
A sequence number is stored in the .SEQ file within each sub directory. Each spool file will use the ever increasing sequence number as the filename with a .pkt extension. To reset the sequence number, just delete the .SEQ file. A new file will automatically be created.
The contents of the spool file is a serialized dump of $self->{packet}. It uses JSON as the serialization method. JSON was chosen because it is a widely known and used format for serializing data structures.
This will initialize the base object. It takes the following parameters:
This is the directory to use for spool files.
The name of the lock file to use. Defaults to 'spool'.
The extension to use on the spool file. Defaults to '.pkt'.
The name of the sequence file to use. Defaults to '.SEQ'.
The file permissions for any created file. Default 0664.
This will clear the internal data storeage. This method should be overridden by the more specific needs of sub classes.
This method will store a buffer into the internal data storage. This buffer should be something that can be serialized into a JSON formated string.
This will write a new spool file using the interal data storage. Each evocation of write() will create a new spool file. This method should be overridden by the more specific needs of sub classes.
This will read the contents of spool file and return a data structure. This method should be overridden by the more specific needs of sub classes.
Example
$packet = $spl->read($file);
This will scan the spool directory looking for items to process. It returns and array of files to process.
This method will delete the file from the spool directory.
This method will return a count of the items in the spool directory.
This method will retreive a filename from the spool directory.
This method will get the current file extension.
This method will get the current lock file name.
This method will get the current seguence file name.
This method will get/set the current spool directory.
XAS
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (C) 2012 by Kevin L. Esteb
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8 or, at your option, any later version of Perl 5 you may have available.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.