Type::Coercion - a set of coercions to a particular target type constraint
This module is covered by the Type-Tiny stability policy.
Moose-style constructor function.
Create a Type::Coercion from two existing Type::Coercion objects.
A name for the coercion. These need to conform to certain naming rules (they must begin with an uppercase letter and continue using only letters, digits 0-9 and underscores).
Optional; if not supplied will be an anonymous coercion.
A name to display for the coercion when stringified.
These don't have to conform to any naming rules.
Optional; a default name will be calculated from the
The package name of the type library this coercion is associated with. Optional. Informational only: setting this attribute does not install the coercion into the package.
Weak reference to the target type constraint (i.e. the type constraint which the output of coercion coderefs is expected to conform to).
Arrayref of source-type/code pairs.
Don't set this in the constructor; use the
add_type_coercions method instead.
Coderef to coerce a value (
The general point of this attribute is that you should not set it, and rely on the lazily-built default. Type::Coerce will usually generate a pretty fast coderef, inlining all type constraint checks, etc.
A Moose::Meta::TypeCoercion object equivalent to this one. Don't set this manually; rely on the default built one.
Boolean; default false.
A frozen coercion cannot have
add_type_coercions called upon it.
Returns true iff the coercion does not have a
For non-anonymous coercions that have a library,
returns a qualified
"Library::Type" sort of name.
returns the same as
add_type_coercions($type1, $code1, ...)
Takes one or more pairs of Type::Tiny constraints and coercion code, creating an ordered list of source types and coercion codes.
Coercion codes can be expressed as either a string of Perl code (this includes objects which overload stringification),
or a coderef (or object that overloads coderefification).
In either case,
the value to be coerced is
Coerce the value to the target type.
Returns the coerced value, or the original value if no coercion was possible.
Coerce the value to the target type, and throw an exception if the result does not validate against the target type constraint.
Returns the coerced value.
Returns true iff this coercion has a coercion from the source type.
Returns the special string
"0 but true" if no coercion should actually be necessary for this type.
if a coercion coerces to a theoretical "Number" type,
there is probably no coercion necessary for values that already conform to the "Integer" type.)
Returns true iff the value could be coerced by this coercion.
Returns the special string
"0 but true" if no coercion would be actually be necessary for this value (due to it already meeting the target type constraint).
Returns true iff the coercion can be inlined.
inline_coerce from Type::Tiny.
frozen to true.
There is no
Called automatically by Type::Tiny sometimes.
If Moose is loaded, then the combination of these methods is used to mock a Moose::Meta::TypeCoercion.
The following methods are used for parameterized coercions, but are not fully documented because they may change in the near future:
The following methods exist for Moose/Mouse compatibility, but do not do anything useful.
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.
plus_coercionsmethod provided by Type::Tiny should make this simple.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny.
Toby Inkster <firstname.lastname@example.org>.
This software is copyright (c) 2013-2014 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.