NAME
TLC::Example - type constraint library
TYPES
This type constraint library is even more basic that Type::Tiny. Exported types may be combined using Foo | Bar
but parameterized type constraints like Foo[Bar]
are not supported.
Any
Based on Any in Types::Standard.
The Any
constant returns a blessed type constraint object. is_Any($value)
checks a value against the type and returns a boolean. assert_Any($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Any );
Array
Based on ArrayRef in Types::Standard.
The Array
constant returns a blessed type constraint object. is_Array($value)
checks a value against the type and returns a boolean. assert_Array($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Array );
Directory
Based on Dir in Types::Path::Tiny.
The Directory
constant returns a blessed type constraint object. is_Directory($value)
checks a value against the type and returns a boolean. assert_Directory($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Directory );
File
Based on File in Types::Path::Tiny.
The File
constant returns a blessed type constraint object. is_File($value)
checks a value against the type and returns a boolean. assert_File($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :File );
Hash
Based on HashRef in Types::Standard.
The Hash
constant returns a blessed type constraint object. is_Hash($value)
checks a value against the type and returns a boolean. assert_Hash($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Hash );
Integer
Based on Int in Types::Standard.
The Integer
constant returns a blessed type constraint object. is_Integer($value)
checks a value against the type and returns a boolean. assert_Integer($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Integer );
NonEmptyString
Based on NonEmptyStr in Types::Common::String.
The NonEmptyString
constant returns a blessed type constraint object. is_NonEmptyString($value)
checks a value against the type and returns a boolean. assert_NonEmptyString($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :NonEmptyString );
Null
Based on Undef in Types::Standard.
The Null
constant returns a blessed type constraint object. is_Null($value)
checks a value against the type and returns a boolean. assert_Null($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Null );
Number
Based on Num in Types::Standard.
The Number
constant returns a blessed type constraint object. is_Number($value)
checks a value against the type and returns a boolean. assert_Number($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Number );
Object
Based on Object in Types::Standard.
The Object
constant returns a blessed type constraint object. is_Object($value)
checks a value against the type and returns a boolean. assert_Object($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Object );
Path
Based on Path in Types::Path::Tiny.
The Path
constant returns a blessed type constraint object. is_Path($value)
checks a value against the type and returns a boolean. assert_Path($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :Path );
String
Based on Str in Types::Standard.
The String
constant returns a blessed type constraint object. is_String($value)
checks a value against the type and returns a boolean. assert_String($value)
checks a value against the type and throws an error.
To import all of these functions:
use TLC::Example qw( :String );
TYPE CONSTRAINT METHODS
For any type constraint Foo the following methods are available:
Foo->check( $value ) # boolean
Foo->get_message( $value ) # error message, even if $value is ok
Foo->validate( $value ) # error message, or undef if ok
Foo->assert_valid( $value ) # returns true, dies if error
Foo->assert_return( $value ) # returns $value, or dies if error
Foo->to_TypeTiny # promotes the object to Type::Tiny
Objects overload stringification to return their name and overload coderefification to call assert_return
.
The objects as-is can be used in Moo or Mite isa
options.
has myattr => (
is => 'rw',
isa => Foo,
);
They cannot be used as-is in Moose or Mouse, but can be promoted to Type::Tiny and will then work:
has myattr => (
is => 'rw',
isa => Foo->to_TypeTiny,
);