NAME
Data::Queue::Persistent - Perisistent database-backed queue
SYNOPSIS
use Data::Queue::Persistent;
my $q = Data::Queue::Persistent->new(
table => 'persistent_queue',
dsn => 'dbi:SQLite:dbname=queue.db',
id => 'testqueue',
);
$q->add('first', 'second', 'third', 'fourth');
$q->remove; # returns 'first'
$q->remove(2); # returns ('second', 'third')
$q->empty; # removes everything
DESCRIPTION
This is a simple module to keep a persistent queue around. It is just a normal implementation of a queue, except it is backed by a database so that when your program exits the data won't disappear.
EXPORT
None by default.
Methods
new(%opts)
Creates a new persistent data queue object. This will also initialize the database storage, and load the saved queue data if it already exists.
Options:
dsn: DSN for database connection
dbh: Already initialized DBI connection handle
id: The ID of this queue. You can have multiple queues stored in the same table, distinguished by their IDs.
user: The username for database connection (optional)
pass: The password for database connection (optional)
table: The table name to use ('persistent_queue' by default)
add(@items)
Adds a list of items to the queue
remove($count)
Removes $count (1 by default) items from the queue and returns them. Returns value if no $count specified, otherwise returns an array of values.
all
Returns all elements in the queue. Does not modify the queue.
empty
Removes all elements from the queue
unshift(@items)
Alias for
add(@items)
shift($count)
Alias for
remove($count)
SEE ALSO
Any data structures book
AUTHOR
Mischa Spiegelmock, <mspiegelmock@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2007 by Mischa Spiegelmock
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.4 or, at your option, any later version of Perl 5 you may have available.