XAS::Lib::Modules::Spool - A Perl extension for the XAS environment
use XAS::Factory; my $spl = XAS::Factory->module( spool => { -directory => 'spool', -lock => 'spool', } ); $spl->write('this is some data'); $spl->write("This is some other data"); my @files = $spl->scan(); foreach my $file (@files) { my $packet = $spl->read($file); print $packet; $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 file name with a .pkt extension. To reset the sequence number, just delete the .SEQ file. A new file will automatically be created.
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 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 write a new spool file using the supplied "packet". Each evocation of write() will create a new spool file. This method should be overridden by the more specific needs of sub classes.
The data that will be written to the spool file.
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 retrieve a file name from the spool directory.
This method will get the current file extension.
This method will get the current locks name.
This method will get the current sequence file name.
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (C) 2014 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.
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.