-
-
14 Sep 2006 14:14:18 UTC
- Distribution: Declare-Constraints-Simple
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (3)
- Testers (2628 / 11 / 4)
- Kwalitee
Bus factor: 0- 98.21% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (29.63KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Robert 'phaylon' Sedlacek
- Dependencies
- Carp::Clan
- Class::Inspector
- Scalar::Util
- aliased
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Declare::Constraints::Simple::Library::Operators - Operators
SYNOPSIS
# all hast to be valid my $and_constraint = And( IsInt, Matches(qr/0$/) ); # at least one has to be valid my $or_constraint = Or( IsInt, HasLength ); # only one can be valid my $xor_constraint = XOr( IsClass, IsObject ); # reverse validity my $not_an_integer = Not( IsInt ); # case valid, validate 'bar' key depending on 'foo' keys value my $struct_prof = And( IsHashRef, CaseValid( OnHashKeys(foo => IsEq("FooArray")), OnHashKeys(bar => IsArrayRef), OnHashKeys(foo => IsEq("FooHash")), OnHashKeys(bar => IsHashRef) ));
DESCRIPTION
This module contains the frameworks operators. These constraint like elements act on the validity of passed constraints.
OPERATORS
And(@constraints)
Is true if all passed
@constraints
are true on the value. Returns the result of the first failing constraint.Or(@constraints)
Is true if at least one of the passed
@contraints
is true. Returns the last failing constraint's result if false.XOr(@constraints)
Valid only if a single one of the passed
@constraints
is valid. Returns the last failing constraint's result if false.Not($constraint)
This is valid if the passed
$constraint
is false. The main purpose of this operator is to allow the easy reversion of a constraint's trueness.CaseValid($test, $conseq, $test2, $conseq2, ...)
This runs every given
$test
argument on the value, until it finds one that returns true. If none is found, false is returned. On a true result, howver, the corresponding$conseq
constraint is applied to the value and it's result returned. This allows validation depending on other properties of the value:my $flexible = CaseValid( IsArrayRef, And( HasArraySize(1,5), OnArrayElements(0 => IsInt) ), IsHashRef, And( HasHashElements(qw( head tail )), OnHashKeys(head => IsInt) ));
Of course, you could model most of it probably with the other operators, but this is a bit more readable. For default cases use
ReturnTrue
from Declare::Constraints::Simple::Library::General as test.SEE ALSO
Declare::Constraints::Simple, Declare::Constraints::Simple::Library
AUTHOR
Robert 'phaylon' Sedlacek
<phaylon@dunkelheit.at>
LICENSE AND COPYRIGHT
This module is free software, you can redistribute it and/or modify it under the same terms as perl itself.
Module Install Instructions
To install Declare::Constraints::Simple, copy and paste the appropriate command in to your terminal.
cpanm Declare::Constraints::Simple
perl -MCPAN -e shell install Declare::Constraints::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.