Type::Tiny::Manual - an overview of Type::Tiny
Type::Tiny is a small framework for writing type constraints and organising them into type libraries. Although inspired by Moose's type constraint API, it has no non-core dependencies, and can be used with Moose, Mouse and Moo.
It provides a small Moose-inspired library of built-in type constraints.
Libraries - how to build a type library with Type::Tiny, Type::Library and Type::Utils
Using with Moose - how to use Type::Tiny and Type::Library with Moose
Using with Mouse - how to use Type::Tiny and Type::Library with Mouse
Using with Moo - how to use Type::Tiny and Type::Library with Moo
Type::Tiny and friends don't need to be used within an OO framework. See FreeMind::Node for an example that does not.
Type::Tiny is similar in aim to Specio. The major differences are that Type::Tiny is "tiny"; and Type::Tiny dispenses with the idea of a type registry and stringy access to type constraints.
Type::Tiny libraries expose a similar interface to MooseX::Types libraries. In most cases you should be able to rewrite a MooseX::Types library to use Type::Tiny pretty easily.
Type::Tiny is faster and supports coercions.
Type::Tiny type constraints are designed as immutable objects. Once you've created a constraint, rather than modifying it you generally create child constraints to do what you need.
Type::Coercion objects, on the other hand, are mutable. Coercion routines can be added at any time during the object's lifetime.
This combination of features means that if you create a Type::Tiny type constraint, then create a Moose or Mouse type from it (the moose_type and mouse_type lazily built attributes), and then add coercions to the Type::Tiny constraint, the Moose/Mouse constraint will not see them.
moose_type
mouse_type
In general you should avoid adding coercions to a type constraint once the type constraint has started being used. Add coercions straight after defining the type. The plus_coercions method (which returns a new type constraint with extra coercions, so doesn't violate immutability) is a better technique than adding coercions willy-nilly during the course of a constraint's lifetime.
plus_coercions
I do consider this to be an issue that needs resolving in a future release. The likely solution will be to have the ability to "freeze" a Type::Coercion object, and then change the moose_type and mouse_type lazy builders to make them automatically freeze the type's associated coercion.
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::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Type::Tiny
CPAN shell
perl -MCPAN -e shell install Type::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.