NAME
Stack::Presistent - A persistent stack
SYNOPSIS
This module implements a named, persistent stack for usage by programs that need to recover the items on a stack when something unexpected happens. The stack is LIFO based.
DESCRIPTION
This module can be used as follows:
use Stack::Presistent;
$stack = Stack::Presistent->new();
$stack->push('default', 'some really cool stuff');
printf("There are %s items on the stack\n", $stack->items('default'));
printf("My data is: %s\n", $stack->pop('default'));
The main purpose of this module was to have a persistent stack that could survive the restart of a program. Multiple, named stacks can be maintained.
METHODS
- new
-
There are several named parameters that can be used with this method. Since this module use Cache::FastMmap to manage the backing store. You should read that modules documentation. They are the following:
- -initialize
-
This initializes the stacks backing cache. You will not want to do this if your program needs to retireve items after a restart. The default is to not initialize.
- -pages
-
What the number of pages for your stacks backing cache should be. The default is 64.
- -size
-
The size of those pages in bytes. The default is 64KB.
- -expiration
-
The expiration of item with the stacks cache. The default is 24 hours.
- -filename
-
The name of the file that is being used. The default is /tmp/stack-presistent.cache.
- Example
-
$stack = Stack::Presistent->new(-filename => '/tmp/stack.cache');
- push
-
Push a data element onto the named stack.
- Example
-
$stack->push('default', $data);
- pop
-
Remove a data element from the top of a named stack. Once an element has been "popped" it is no longer avaiable within the cache.
- Example
-
$data = $stack->pop('default');
- peek
-
Retrieve the data element from the top of the stack. The data element is not removed from the stack. To remove an element, you need to use pop().
- Example
-
$data = $stack->peek('default');
- items
-
Return the number of data elements that are currently on the stack.
- Example
-
$items1 = $stack->items('default'); $items2 = $stack->items('worker');
- clear
-
Remove all data elements from the stack. Once a stack has been "cleared" there are no data elements left within the cache.
- Example
-
$stack->clear('default');
- dump
-
Dump all the backing cache for the stack. This is can be used for debugging purposes.
- Example
-
$stack->dump('default');
ACCESSORS
- handle
-
This accessor returns the underling handle for Cache::FastMmap. You can then use any of methods that are available to that module.
- Example
-
$handle = $stack->handle; $handle->purge();
EXPORT
None by default.
SEE ALSO
Cache::FastMmap
AUTHOR
Kevin L. Esteb, <kesteb@wsipc.org>
COPYRIGHT AND LICENSE
Copyright (C) 2007 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.5 or, at your option, any later version of Perl 5 you may have available.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 341:
You forgot a '=back' before '=head1'
- Around line 359:
You forgot a '=back' before '=head1'