The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

XAS::Lib::Modules::Spool - A Perl extension for the XAS environment

SYNOPSIS

 use XAS::Factory;

 my $spl = XAS::Factory->module(
     spool => {
         -directory => '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);

 }

DESCRIPTION

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.

METHODS

new

This will initialize the base object. It takes the following parameters:

-directory

This is the directory to use for spool files.

-lockfile

The name of the lock file to use. Defaults to 'spool'.

-extension

The extension to use on the spool file. Defaults to '.pkt'.

-seqfile

The name of the sequence file to use. Defaults to '.SEQ'.

-mask

The file permissions for any created file. Default 0664.

write($packet)

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.

$packet

The data that will be written to the spool file.

read($filename)

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);

scan

This will scan the spool directory looking for items to process. It returns and array of files to process.

delete($filename)

This method will delete the file from the spool directory.

count

This method will return a count of the items in the spool directory.

get

This method will retrieve a file name from the spool directory.

ACCESORS

extension

This method will get the current file extension.

lockfile

This method will get the current lock file name.

segfile

This method will get the current sequence file name.

SEE ALSO

XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 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.8 or, at your option, any later version of Perl 5 you may have available.

See http://dev.perl.org/licenses/ for more information.