Moose::Util::TypeConstraints - Type constraint system for Moose
use Moose::Util::TypeConstraints; type Num => where { Scalar::Util::looks_like_number($_) }; subtype Natural => as Num => where { $_ > 0 }; subtype NaturalLessThanTen => as Natural => where { $_ < 10 };
This module provides Moose with the ability to create type contraints to be are used in both attribute definitions and for method argument validation.
This is NOT a type system for Perl 5.
The type and subtype constraints are basically functions which will validate their first argument. If called with no arguments, they will return themselves (this is syntactic sugar for Moose attributes).
This module also provides a simple hierarchy for Perl 5 types, this could probably use some work, but it works for me at the moment.
Any Value Int Str Ref ScalarRef ArrayRef HashRef CodeRef RegexpRef Object
Suggestions for improvement are welcome.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <stevan@iinteractive.com>
Copyright 2006 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Moose
CPAN shell
perl -MCPAN -e shell install Moose
For more information on module installation, please visit the detailed CPAN module installation guide.