NAME
Data::RefQueue - Queue system based on references and scalars.
VERSION
This document describes version 0.3.
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.
SEE ALSO
perl.
AUTHOR
Ask Solem, <ask@0x61736b.net>
LICENSE AND COPYRIGHT
Copyright (c), 2002-2007 Ask Solem ask@0x61736b.net
.
All rights reserved.
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.6 or, at your option, any later version of Perl 5 you may have available.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.