Tie::Assert::CheckFactory - Creates checks for Tie::Assert
This document refers to version 0.12 of Tie::Assert::CheckFactory, released Oct 13th 2004.
# 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;
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.
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.
As mentioned under 'CONSTRUCTOR AND INITIALISATION' above, the following can be called either procedurally or in an object-oriented style as you see fit.
The variable must contain an array reference.
The variable must contain an object reference which supports the listed @methods.
The variable must contain a code reference.
The variable must contain a glob reference. (Currently untested)
The variable must contain a hash reference.
The variable must be an integer.
The variable must contain an object reference which must either be of type $class, or a descendant.
The variable must contain an lvalue reference. (Currently untested)
The variable cannot be lower than $min.
The variable cannot be larger than $max.
The variable must have a numeric value.
The variable must be in the range $min-$max, inclusive.
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.
The variable must match the regular expression provided.
The variable must be a reference to a scalar.
The variable must remain a valid string, it won't be stringified in order to comply.
No known bugs.
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.
Paul Golds (Paul.Golds@GMail.com)
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.