The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::Array::BoundedIndex - Bounded arrays

SYNOPSIS

  use Tie::Array::BoundedIndex;
  tie @array, "Tie::Array::BoundedIndex", upper => 100;
  tie @array, "Tie::Array::BoundedIndex", lower => 10, upper => 20;

  my @array : Bounded(upper => 20);

DESCRIPTION

Tie::Array::BoundedIndex allows you to create arrays which perform bounds checking upon their indices. A fatal exception will be thrown upon an attempt to go outside the specified bounds.

Usage:

  tie @array, "Tie::Array::BoundedIndex",
              upper => $upper_limit [, lower => $lower_limit]

A mandatory upper limit is specified with the upper keyword. An optional lower limit is specified with the lower keyword; the default is 0. Each specifies the limit of array indices that may be used. Any attempt to exceed them results in the fatal exception "index <index> out of range [<lower>, <upper>]".

The bounds must be integers greater than or equal to zero with the upper bound greater than or equal to the lower bound.

Use with Attribute::Handlers

Damian Conway's Attribute::Handlers module provides a nice alternative declaration syntax. If you have it installed, then you can declare bounded arrays with:

  my @array : Bounded(upper => 20)

or

  my @array : Bounded(lower => 10, upper => 20)

BUGS

Slow. But then, what were you expecting? If you want fast bounded arrays, submit an XS version (with tests) and I'll add it.

AUTHOR

Peter Scott, cpan@PSDT.com.

This module is an expanded version of an example developed in the book ``Perl Medic: Transforming Legacy Code''. See http://www.perlmedic.com.

SEE ALSO

perltie, Tie::Array.