NAME
Data::RefQueue - Queue system based on references and scalars.
SYNOPSIS
use Data::RefQueue;
# ###
# These are the id's we need to fetch, and this is the
# order we want to return.
my $refq = new RefQueue (32, 123, 39, 20, 33, 123);
# ### get id's we already have in cache.
foreach my $obj_id (@{$refq->not_filled}) {
my $objref = get_obj_from_cache($obj_id);
if($objref) {
$refq->save($objref)
} else {
$refq->next;
}
}
$refq->reset;
# ### fetch the rest from the database.
my $query = build_select_query(@{$refq->not_fille});
$db->query($query);
while(my $result = $db->fetchrow_hash) {
my $objref = build_obj_from_db_result($result);
$refq->insert_at($objref->id, $objref);
}
# ### remove the id's we didn't find.
$refq->cleanse;
my $final_objects = $refq->queue;
return $final_objects;
DESCRIPTION
Data::RefQueue is a Queue system based on references and scalars, where the references are filled and scalars are unfilled positions.
A typical queue could look something like:
$refq->queue = [SCALAR(0x8109fb0), 1, 32, 128, 230, SCALAR(0x8109fb0), 140];
Element 0 and 5 are filled positions, which is proved by:
print join("\n> ", $refq->filled);
> SCALAR(0x8109fb0)
> SCALAR(0x8109fb0)
$refq->save($value) saves a value into the next availible position. etc.
METHODS
- data::refqueue new(string pkg, array values)
-
Create a new RefQueue queue starting with @values.
- arrayref queue(data::refqueue q)
-
The queue itself.
- int setpos(data::refqueue q, int pos)
-
Set current queue position. Wraps around if higher/lower than availible elements.
- int getpos(data::refqueue q)
-
Get current queue position.
- int size(data::refqueue q)
-
Return the number of elements in the queue.
- void set(data::refqueue q, array values)
-
Initialize queue, with values @values.
- void next(data::refqueue q)
-
Set position to the next availible position.
- void next(data::refqueue q)
-
Set position to the previous availible position.
- void reset(data::refqueue q)
-
Set queue position to 0.
- void cleanse(data::refqueue q)
-
Remove all positions not filled.
- arrayref not_filled(data::refqueue q)
-
Return an array with the values not filled.
- arrayref filled(data::refqueue q)
-
Return an array with the values filled.
- void* fetch(data::refqueue q)
-
Fetch the value in the current position.
- void delete(data::refqueue q)
-
Delete the contents of the current position.
- void save(data::refqueue q, void* value)
-
Save something into the current position and set position to the next availible element in the queue.
- void remove(data::refqueue)
-
Remove the current position entirely, decrementing the size of the queue by one.
- int insert_at(data::refqueue q, void* key, void* value)
-
Find the element that contains 'key' and replace key with value.
EXPORT
This module has nothing to export.
AUTHOR
Ask Solem Hoel, <ask@unixmonks.net>
SEE ALSO
perl.