Stack::Persistent - A persistent stack
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.
This module can be used as follows:
use Stack::Persistent; $stack = Stack::Persistent->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.
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:
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.
What the number of pages for your stacks backing cache should be. The default is 64.
The size of those pages in bytes. The default is 64KB.
The expiration of item with the stacks cache.
The name of the file that is being used. The default is /tmp/stack-persistent.cache.
$stack = Stack::Persistent->new(-filename => '/tmp/stack.cache');
Push a data element onto the named stack.
$stack->push('default', $data);
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.
$data = $stack->pop('default');
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().
$data = $stack->peek('default');
Return the number of data elements that are currently on the stack.
$items1 = $stack->items('default'); $items2 = $stack->items('worker');
Remove all data elements from the stack. Once a stack has been "cleared" there are no data elements left within the cache.
$stack->clear('default');
Dump all the backing cache for the stack. This is can be used for debugging purposes.
$stack->dump('default');
This accessor returns the underling handle for Cache::FastMmap. You can then use any of methods that are available to that module.
$handle = $stack->handle; $handle->purge();
None by default.
Cache::FastMmap
Kevin L. Esteb, <kesteb@wsipc.org>
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:
You forgot a '=back' before '=head1'
To install Stack::Persistent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Stack::Persistent
CPAN shell
perl -MCPAN -e shell install Stack::Persistent
For more information on module installation, please visit the detailed CPAN module installation guide.