The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Moose::Util::TypeConstraints - Type constraint system for Moose

SYNOPSIS

  use Moose::Util::TypeConstraints;

  type Num => where { Scalar::Util::looks_like_number($_) };
  
  subtype Natural 
      => as Num 
      => where { $_ > 0 };
  
  subtype NaturalLessThanTen 
      => as Natural
      => where { $_ < 10 };

DESCRIPTION

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.

FUNCTIONS

Type Constraint Constructors

type
subtype
as
where

Built-in Type Constraints

Any
Value
Int
Str
Ref
ArrayRef
CodeRef
HashRef
RegexpRef
ScalarRef
Object

BUGS

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.

AUTHOR

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

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.