Kevin L. Esteb > XAS-0.04 > XAS::Lib::Spool

Download:
XAS-0.04.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source   Latest Release: XAS-0.05

NAME ^

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

SYNOPSIS ^

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

 }

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 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.

METHODS ^

new

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

-spooldir

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.

clear

This will clear the internal data storeage. This method should be overridden by the more specific needs of sub classes.

packet($buffer)

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.

write

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.

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 retreive a filename 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 seguence file name.

MUTATORS ^

spooldir

This method will get/set the current spool directory.

SEE ALSO ^

XAS

AUTHOR ^

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

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: