Type::API::Constraint - a rule that a value can be checked against, to determine whether it passes or fails
Implementations of this interface are objects and MUST provide the following methods:
$constraint->check($value)
Checks that the value meets the constraint. Under normal operation should return true or false to indicate a pass or failure.
Exceptions should not be thrown when a value simply fails the constraint, but may be used for other exceptional conditions. (For example, if the check requires a database lookup to determine pass or failure, but the database is unavailable.)
$constraint->get_message($value)
Generates an message explaining that the value has failed the type constraint, and returns this messages as a string. This method does not need to check whether the value genuinely fails the constraint; it can assume that the check method has already been called.
Implementations MAY advertise that they support this interface by returning true for $constraint->DOES("Type::API::Constraint").
$constraint->DOES("Type::API::Constraint")
The following CPAN classes are known to implement Type::API::Constraint:
Moose::Meta::TypeConstraint (and its subclasses)
MooseX::Meta::TypeDecorator
Mouse::Meta::TypeConstraint
MouseX::Meta::TypeDecorator
Specio::Constraint::Simple (and several other classes in the Specio distribution)
Type::Tiny (and its subclasses)
Some tools can make use of objects implementing Type::API::Constraint:
Data::Validator
"Experimental experimental feature: Type expressions" in Function::Parameters
Scalar::Does
Type::Tie
Others, such as Moose and Mouse require type constraints that implement a superset of this functionality.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Type::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Type::API
CPAN shell
perl -MCPAN -e shell install Type::API
For more information on module installation, please visit the detailed CPAN module installation guide.