1Moose::Meta::TypeConstrUasienrt(C3o)ntributed Perl DocumMeonotsaet:i:oMneta::TypeConstraint(3)
2
3
4

NAME

6       Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
7

DESCRIPTION

9       This class represents a single type constraint. Moose's built-in type
10       constraints, as well as constraints you define, are all stored in a
11       Moose::Meta::TypeConstraint::Registry object as objects of this class.
12

INHERITANCE

14       "Moose::Meta::TypeConstraint" is a subclass of Class::MOP::Object.
15

METHODS

17       Moose::Meta::TypeConstraint->new(%options)
18           This creates a new type constraint based on the provided %options:
19
20           ·       name
21
22                   The constraint name. If a name is not provided, it will be
23                   set to "__ANON__".
24
25           ·       parent
26
27                   A "Moose::Meta::TypeConstraint" object which is the parent
28                   type for the type being created. This is optional.
29
30           ·       constraint
31
32                   This is the subroutine reference that implements the actual
33                   constraint check. This defaults to a subroutine which
34                   always returns true.
35
36           ·       message
37
38                   A subroutine reference which is used to generate an error
39                   message when the constraint fails. This is optional.
40
41           ·       coercion
42
43                   A Moose::Meta::TypeCoercion object representing the
44                   coercions to the type. This is optional.
45
46           ·       optimized
47
48                   This is a variant of the "constraint" parameter that is
49                   somehow optimized. Typically, this means incorporating both
50                   the type's constraint and all of its parents' constraints
51                   into a single subroutine reference.
52
53       $constraint->equals($type_name_or_object)
54           Returns true if the supplied name or type object is the same as the
55           current type.
56
57       $constraint->is_subtype_of($type_name_or_object)
58           Returns true if the supplied name or type object is a parent of the
59           current type.
60
61       $constraint->is_a_type_of($type_name_or_object)
62           Returns true if the given type is the same as the current type, or
63           is a parent of the current type. This is a shortcut for checking
64           "equals" and "is_subtype_of".
65
66       $constraint->coerce($value)
67           This will attempt to coerce the value to the type. If the type does
68           have any defined coercions this will throw an error.
69
70       $constraint->check($value)
71           Returns true if the given value passes the constraint for the type.
72
73       $constraint->validate($value)
74           This is similar to "check". However, if the type is valid then the
75           method returns an explicit "undef". If the type is not valid, we
76           call "$self->get_message($value)" internally to generate an error
77           message.
78
79       $constraint->assert_valid($value)
80           Like "check" and "validate", this method checks whether $value is
81           valid under the constraint.  If it is, it will return true.  If it
82           is not, an exception will be thrown with the results of
83           "$self->get_message($value)".
84
85       $constraint->name
86           Returns the type's name, as provided to the constructor.
87
88       $constraint->parent
89           Returns the type's parent, as provided to the constructor, if any.
90
91       $constraint->has_parent
92           Returns true if the type has a parent type.
93
94       $constraint->parents
95           A synonym for "parent". This is useful for polymorphism with types
96           that can have more than one parent.
97
98       $constraint->constraint
99           Returns the type's constraint, as provided to the constructor.
100
101       $constraint->get_message($value)
102           This generates a method for the given value. If the type does not
103           have an explicit message, we generate a default message.
104
105       $constraint->has_message
106           Returns true if the type has a message.
107
108       $constraint->message
109           Returns the type's message as a subroutine reference.
110
111       $constraint->coercion
112           Returns the type's Moose::Meta::TypeCoercion object, if one exists.
113
114       $constraint->has_coercion
115           Returns true if the type has a coercion.
116
117       $constraint->hand_optimized_type_constraint
118           Returns the type's hand optimized constraint, as provided to the
119           constructor via the "optimized" option.
120
121       $constraint->has_hand_optimized_type_constraint
122           Returns true if the type has an optimized constraint.
123
124       $constraint->create_child_type(%options)
125           This returns a new type constraint of the same class using the
126           provided %options. The "parent" option will be the current type.
127
128           This method exists so that subclasses of this class can override
129           this behavior and change how child types are created.
130

BUGS

132       See "BUGS" in Moose for details on reporting bugs.
133

AUTHOR

135       Stevan Little <stevan@iinteractive.com>
136
138       Copyright 2006-2010 by Infinity Interactive, Inc.
139
140       <http://www.iinteractive.com>
141
142       This library is free software; you can redistribute it and/or modify it
143       under the same terms as Perl itself.
144
145
146
147perl v5.12.2                      2010-08-28    Moose::Meta::TypeConstraint(3)
Impressum