1Types::TypeTiny(3) User Contributed Perl Documentation Types::TypeTiny(3)
2
3
4
6 Types::TypeTiny - type constraints used internally by Type::Tiny
7
9 This module is covered by the Type-Tiny stability policy.
10
11 The BoolLike type is currently unstable.
12
14 Dogfooding.
15
16 This isn't a real Type::Library-based type library; that would involve
17 too much circularity. But it exports some type constraints which, while
18 designed for use within Type::Tiny, may be more generally useful.
19
20 Types
21 • StringLike
22
23 Accepts strings and objects overloading stringification.
24
25 • BoolLike
26
27 Accepts undef, "", 0, 1; accepts any blessed object overloading
28 "bool"; accepts any blessed object overloading "0+" to return 0 or
29 1. (Needs to actually call the overloaded operation to check that.)
30
31 Warning: an object which overloads "0+" without also turning on
32 overload fallbacks may actually be useless as a practical boolean.
33 But some common objects such as JSON::PP's booleans overload "0+"
34 instead of overloading "bool" (thankfully with fallbacks enabled!)
35 so we do need to support this.
36
37 The intention of this type is to be a version of Bool which also
38 accepts common boolean objects such as JSON::PP::Boolean. It is
39 currently unstable and the exact definition of the type may change
40 to better implement that intended functionality.
41
42 • HashLike[`a]
43
44 Accepts hashrefs and objects overloading hashification.
45
46 Since Types::TypeTiny 1.012, may be parameterized with another type
47 constraint like HashLike[Int].
48
49 • ArrayLike[`a]
50
51 Accepts arrayrefs and objects overloading arrayfication.
52
53 Since Types::TypeTiny 1.012, may be parameterized with another type
54 constraint like ArrayLike[Int].
55
56 • CodeLike
57
58 Accepts coderefs and objects overloading codification.
59
60 • TypeTiny
61
62 Accepts blessed Type::Tiny objects.
63
64 • _ForeignTypeConstraint
65
66 Any reference which to_TypeTiny recognizes as something that can be
67 coerced to a Type::Tiny object.
68
69 Yes, the underscore is included.
70
71 Coercion Functions
72 to_TypeTiny($constraint)
73 Promotes (or "demotes" if you prefer) a "foreign" type constraint
74 to a Type::Tiny object. Can handle:
75
76 • Moose types (including Moose::Meta::TypeConstraint objects and
77 MooseX::Types::TypeDecorator objects).
78
79 • Mouse types (including Mouse::Meta::TypeConstraint objects).
80
81 • Validation::Class and Validation::Class::Simple objects.
82
83 • Types built using Type::Library::Compiler.
84
85 • Any object which provides "check" and "get_message" methods.
86 (This includes Specio and Type::Nano types.) If the object
87 provides "has_coercion" and coerce methods, these will be used
88 to handle quoting. If the object provides "can_be_inlined" and
89 "inline_check" methods, these will be used to handling
90 inlining. If the object provides a "name" method, this will be
91 assumed to return the type name.
92
93 • Coderefs (but not blessed coderefs or objects overloading "&{}"
94 unless they provide the methods described above!) Coderefs are
95 expected to return true iff $_ passes the constraint. If $_
96 fails the type constraint, they may either return false, or die
97 with a helpful error message.
98
99 • Sub::Quote-enabled coderefs. These are handled the same way as
100 above, but Type::Tiny will consult Sub::Quote to determine if
101 they can be inlined.
102
103 Methods
104 These are implemented so that "Types::TypeTiny->meta->get_type($foo)"
105 works, for rough compatibility with a real Type::Library type library.
106
107 "meta"
108 "type_names"
109 get_type($name)
110 has_type($name)
111 "coercion_names"
112 get_coercion($name)
113 has_coercion($name)
114
116 Please report any bugs to
117 <https://github.com/tobyink/p5-type-tiny/issues>.
118
120 Type::Tiny.
121
123 Toby Inkster <tobyink@cpan.org>.
124
126 This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.
127
128 This is free software; you can redistribute it and/or modify it under
129 the same terms as the Perl 5 programming language system itself.
130
132 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
133 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
134 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
135
136
137
138perl v5.36.0 2023-04-24 Types::TypeTiny(3)