-
-
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::General - General Constraints
SYNOPSIS
# custom error messages my $constraint = And( Message( 'You need to specify a Value', IsDefined ), Message( 'The specified Value is not an Int', IsInt )); # build results my $valid = ReturnTrue; my $invalid = ReturnFalse('Just because');
DESCRIPTION
This library is meant to contain those constraints and constraint-like elements that apply generally to the whole framework.
CONSTRAINTS
Message($message, $constraint)
Overrides the
message
set on the result object for failures in$constraint
. For example:my $message = 'How hard is it to give me a number?'; my $constraint = Message($message, IsNumber); my $result = $constraint->('duh...'); print $result->message, "\n";
The
Message
constraint overrides the error message returned by it's whole subtree, however, theMessage
specification nearest to the point of failure will win. So while thismy $constraint = Message( 'Foo', IsArrayRef( Message( 'Bar', IsInt ))); my $result = $constraint->(['I am not an Integer']); print $result->message;
will print
Bar
, thismy $result = $constraint->('I\'m not even an ArrayRef'); print $result->message;
will output
Foo
.Scope($name, $constraint)
Executes the passed
$constraint
in a newly generated scope named$name
.SetResult($scope, $name, $constraint)
Stores the result ov an evaluation of
$constraint
in$scope
under$name
.IsValid($scope, $name)
Returns a true result if the result
$name
, which has to have been stored previously in the scope named$scope
, was valid.ReturnTrue()
Returns a true result.
ReturnFalse($msg)
Returns a false result containing
$msg
as error message.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.