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

NAME

Tie::Assert::CheckFactory - Creates checks for Tie::Assert

VERSION

This document refers to version 0.12 of Tie::Assert::CheckFactory, released Oct 13th 2004.

SYNOPSIS

  # Create a $age variable which needs to be in the range of
  #  zero to a hundred and twenty.
  my $age;
  tie ($age, 'Tie::Assert::Scalar',
    Tie::Assert::CheckFactory->range(0=>120),
  );

  # Perfectly fine..
  $age = 23;

  # ..causes fatal error.
  $age = 1723;

DESCRIPTION

This module contains prebuilt useful checks for the Tie::Assert module, to use the checks simply include them when you tie() a variable to Tie::Assert::Scalar (..or it's relatives), or pass them in with the add_check() method.

See the documentation for Tie::Assert for more information.

CONSTRUCTOR AND INITIALISATION

Tie::Assert::CheckFactory methods can be called in either OO or procedural style, it makes no difference. The following two code fragments are effectively identical:

  my $factory = Tie::Assert::CheckFactory->new();
  $name->add_filter($factory->regex(qr/^[A-Z][A-Za-z]+$/);

  $name->add_filter(
    Tie::Assert::CheckFactory->regex(qr/^[A-Z][A-Za-z]+$/);

If you choose to use the OO-style calls the constructor takes no parameters.

CLASS/OBJECT METHODS

As mentioned under 'CONSTRUCTOR AND INITIALISATION' above, the following can be called either procedurally or in an object-oriented style as you see fit.

array_ref ()

The variable must contain an array reference.

can (@methods)

The variable must contain an object reference which supports the listed @methods.

code_ref ()

The variable must contain a code reference.

glob_ref ()

The variable must contain a glob reference. (Currently untested)

hash_ref ()

The variable must contain a hash reference.

integer_ok ()

The variable must be an integer.

isa ($class)

The variable must contain an object reference which must either be of type $class, or a descendant.

lvalue_ref ()

The variable must contain an lvalue reference. (Currently untested)

min ($min)

The variable cannot be lower than $min.

max ($max)

The variable cannot be larger than $max.

number_ok ()

The variable must have a numeric value.

range ($min, $max)

The variable must be in the range $min-$max, inclusive.

ref_to ($type_name)

The variable must contain a reference to the supplied typename, often the name of a class the variable is to store.

Note that the standard array, code, glob, hash, lvalue, and scalar types are already covered by other methods provided by this class, such as array_ref, but you can call this yourself if you wish.

regex (qr/regex/i)

The variable must match the regular expression provided.

scalar_ref ()

The variable must be a reference to a scalar.

string_ok ()

The variable must remain a valid string, it won't be stringified in order to comply.

BUGS

No known bugs.

NOTE

This module is ALPHA code, it's seemed stable in a number of projects but the interface is liable to change before the final release.

SEE ALSO

Tie::Aspect, Tie::Aspect::Scalar

AUTHOR

Paul Golds (Paul.Golds@GMail.com)

COPYRIGHT

Copyright (c) 2004, Paul Golds. All rights reserved. This module is free software. It may be used, redistributed, and/or modified under the same terms as Perl itself.