1MooX::Types::MooseLike:U:sBearseC(o3n)tributed Perl DocuMmoeonXt:a:tTiyopnes::MooseLike::Base(3)
2
3
4

NAME

6       MooX::Types::MooseLike::Base - A set of basic Moose-like types for Moo
7

SYNOPSIS

9         package MyPackage;
10         use Moo;
11         use MooX::Types::MooseLike::Base qw(:all);
12
13         has "beers_by_day_of_week" => (
14             isa => HashRef
15         );
16
17         has "current_BAC" => (
18             isa => Num
19         );
20
21         # Also supporting is_$type.  For example, is_Int() can be used as follows
22         has 'legal_age' => (
23             is => 'ro',
24             isa => sub { die "$_[0] is not of legal age"
25                          unless (is_Int($_[0]) && $_[0] > 17) },
26         );
27

DESCRIPTION

29       Moo attributes (like Moose) have an 'isa' property.  This module
30       provides some basic types for this property.  One can import all types
31       with ':all' tag or import a list of types like:
32
33         use MooX::Types::MooseLike::Base qw/HashRef ArrayRef/;
34
35       so one could then declare some attributes like:
36
37         has 'contact' => (
38           is => 'ro',
39           isa => HashRef,
40         );
41         has 'guest_list' => (
42           is => 'ro',
43           isa => ArrayRef[HashRef],
44         );
45
46       These types provide a check that the contact attribute is a "hash"
47       reference, and that the guest_list is an "array of hash" references.
48

TYPES (1st class functions - return a coderef)

50   Any
51       Any type (test is always true)
52
53   Item
54       Synonymous with Any type
55
56   Undef
57       A type that is not defined
58
59   Defined
60       A type that is defined
61
62   Bool
63       A boolean 1|0 type
64
65   Value
66       A non-reference type
67
68   Ref
69       A reference type
70
71   Str
72       A non-reference type where a reference to it is a SCALAR
73
74   Num
75       A number type
76
77   Int
78       An integer type
79
80   ArrayRef
81       An ArrayRef (ARRAY) type
82
83   HashRef
84       A HashRef (HASH) type
85
86   CodeRef
87       A CodeRef (CODE) type
88
89   RegexpRef
90       A regular expression reference type
91
92   GlobRef
93       A glob reference type
94
95   FileHandle
96       A type that is either a builtin perl filehandle or an IO::Handle object
97
98   Object
99       A type that is an object (think blessed)
100

PARAMETERIZED TYPES

102   Parameterizing Types With a Single Type
103       The following types can be parameterized with other types.
104
105       ArrayRef
106
107       For example, ArrayRef[HashRef]
108
109       HashRef
110
111       ScalarRef
112
113       Maybe
114
115       For example, Maybe[Int] would be an integer or undef
116
117   Parameterizing Types With Multiple Types
118       AnyOf
119
120       Check if the attribute is any of the listed types (think union).  Takes
121       a list of types as the argument, for example:
122
123         isa => AnyOf[Int, ArrayRef[Int], HashRef[Int]]
124
125       Note: AnyOf is passed an ArrayRef[CodeRef]
126
127       AllOf
128
129       Check if the attribute is all of the listed types (think intersection).
130       Takes a list of types as the argument. For example:
131
132         isa => AllOf[
133           InstanceOf['Human'],
134           ConsumerOf['Air'],
135           HasMethods['breath', 'dance']
136         ],
137
138   Parameterizing Types With (Multiple) Strings
139       In addition, we have some parameterized types that take string
140       arguments.
141
142       InstanceOf
143
144       Check if the attribute is an object instance of one or more classes.
145       Uses "blessed" and "isa" to do so.  Takes a list of class names as the
146       argument. For example:
147
148         isa => InstanceOf['MyClass','MyOtherClass']
149
150       Note: InstanceOf is passed an ArrayRef[Str]
151
152       ConsumerOf
153
154       Check if the attribute is blessed and consumes one or more roles.  Uses
155       "blessed" and "does" to do so.  Takes a list of role names as the
156       arguments. For example:
157
158         isa => ConsumerOf['My::Role', 'My::AnotherRole']
159
160       HasMethods
161
162       Check if the attribute is blessed and has one or more methods.  Uses
163       "blessed" and "can" to do so.  Takes a list of method names as the
164       arguments. For example:
165
166         isa => HasMethods[qw/postulate contemplate liberate/]
167
168       Enum
169
170       Check if the attribute is one of the enumerated strings.  Takes a list
171       of possible string values. For example:
172
173         isa => Enum['rock', 'spock', 'paper', 'lizard', 'scissors']
174

SEE ALSO

176       MooX::Types::MooseLike::Numeric - an example of building subtypes.
177
178       MooX::Types::SetObject - an example of building parameterized types.
179
180       MooX::Types::MooseLike::Email, MooX::Types::MooseLike::DateTime
181

AUTHOR

183       Mateu Hunter "hunter@missoula.org"
184

THANKS

186       mst has provided critical guidance on the design
187
189       Copyright 2011-2015 Mateu Hunter
190

LICENSE

192       You may distribute this code under the same terms as Perl itself.
193
194
195
196perl v5.32.0                      2020-07-28   MooX::Types::MooseLike::Base(3)
Impressum