Gavin Carr > List-MRU-0.04 > List::MRU

Download:
List-MRU-0.04.tar.gz

Dependencies

Annotate this POD

Related Modules

Tie::Cache::LRU
more...
By perlmonks.org
View/Report Bugs
Module Version: 0.04   Source  

NAME ^

List::MRU - Perl module implementing a simple fixed-size MRU-ordered list.

SYNOPSIS ^

  use List::MRU;

  # Constructor
  $lm = List::MRU->new(max => 20);

  # Constructor with explicit 'eq' subroutine for obj equality tests
  $lm = List::MRU->new(max => 20, 'eq' => sub {
    $_[0]->stringify eq $_[1]->stringify
  });

  # Constructor using explicit UUIDs
  $lm - List::MRU->new(max => 5, uuid => 1);

  # Add item, moving to head of list if already exists
  $lm->add($item);
  # Add item, moving to head of list if $uuid matches or object already exists
  $lm->add($item, $uuid);

  # Iterate in most-recently-added order
  for $item ($lm->list) {
    print "$item\n";
  }
  # each-style iteration
  while (($item, $uuid) = $lm->each) {
    print "$item, $uuid\n";
  }

  # Item deletion
  $lm->delete($item);
  $lm->delete(uuid => $uuid);

  # Accessors
  $max = $lm->max;        # max items in list
  $count = $lm->count;    # current items in list

DESCRIPTION ^

Perl module implementing a simple fixed-size most-recently-used- (MRU)-ordered list of values/objects. Well, really it's a most- recently-added list - items added to the list are just promoted to the front of the list if they already exist, otherwise they are added there.

Works fine with with non-scalar items, but you will need to supply an explicit 'eq' subroutine to the constructor to handle testing for the 'same' object (or alternatively have overloaded the 'eq' operator for your object).

List::MRU also supports having explicit UUIDs attached to items, allowing List::MRU items to be modified, instead of a change just creating a new entry.

SEE ALSO ^

Tie::Cache::LRU, which was kind of what I wanted, but didn't retain ordering.

AUTHOR ^

Gavin Carr <gavin@openfusion.com.au>

COPYRIGHT AND LICENSE ^

Copyright 2005-2006 by Open Fusion Pty. Ltd.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: