Data::RefQueue - Queue system based on references and scalars.
This document describes version 0.3.
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;
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)
$refq->save($value) saves a value into the next availible position. etc.
Create a new RefQueue queue starting with @values.
The queue itself.
Set current queue position. Wraps around if higher/lower than availible elements.
Get current queue position.
Return the number of elements in the queue.
Initialize queue, with values @values.
Set position to the next availible position.
Set position to the previous availible position.
Set queue position to 0.
Remove all positions not filled.
Return an array with the values not filled.
Return an array with the values filled.
Fetch the value in the current position.
Delete the contents of the current position.
Save something into the current position and set position to the next availible element in the queue.
Remove the current position entirely, decrementing the size of the queue by one.
Find the element that contains 'key' and replace key with value.
This module has nothing to export.
perl.
Ask Solem, <ask@0x61736b.net>
Copyright (c), 2002-2007 Ask Solem ask@0x61736b.net.
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.
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.
To install Data::RefQueue, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::RefQueue
CPAN shell
perl -MCPAN -e shell install Data::RefQueue
For more information on module installation, please visit the detailed CPAN module installation guide.