← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 01.HTTP.t
  Run on Tue May 4 15:25:55 2010
Reported on Tue May 4 15:26:24 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm
Statements Executed 603
Statement Execution Time 2.41ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11112.2ms12.5msMoose::Meta::TypeConstraint::::BEGIN@6Moose::Meta::TypeConstraint::BEGIN@6
2262362µs1.44msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
7442218µs312µsMoose::Meta::TypeConstraint::::__ANON__[:8]Moose::Meta::TypeConstraint::__ANON__[:8]
2311168µs560µsMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
511133µs238µsMoose::Meta::TypeConstraint::::_compile_subtypeMoose::Meta::TypeConstraint::_compile_subtype
2322123µs730µsMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
1711105µs1.09msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
171168µs91µsMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
51149µs66µsMoose::Meta::TypeConstraint::::_collect_all_parentsMoose::Meta::TypeConstraint::_collect_all_parents
11115µs19µsMoose::Meta::TypeConstraint::::BEGIN@4Moose::Meta::TypeConstraint::BEGIN@4
11113µs17µsMoose::Meta::TypeConstraint::::_compile_typeMoose::Meta::TypeConstraint::_compile_type
11111µs52µsMoose::Meta::TypeConstraint::::BEGIN@8Moose::Meta::TypeConstraint::BEGIN@8
1118µs19µsMoose::Meta::TypeConstraint::::BEGIN@5Moose::Meta::TypeConstraint::BEGIN@5
1118µs43µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
1117µs61µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
1117µs32µsMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
2225µs5µsMoose::Meta::TypeConstraint::::__ANON__[:30]Moose::Meta::TypeConstraint::__ANON__[:30]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:253]Moose::Meta::TypeConstraint::__ANON__[:253]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:266]Moose::Meta::TypeConstraint::__ANON__[:266]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:26]Moose::Meta::TypeConstraint::__ANON__[:26]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:279]Moose::Meta::TypeConstraint::__ANON__[:279]
0000s0sMoose::Meta::TypeConstraint::::assert_validMoose::Meta::TypeConstraint::assert_valid
0000s0sMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
0000s0sMoose::Meta::TypeConstraint::::coerceMoose::Meta::TypeConstraint::coerce
0000s0sMoose::Meta::TypeConstraint::::equalsMoose::Meta::TypeConstraint::equals
0000s0sMoose::Meta::TypeConstraint::::get_messageMoose::Meta::TypeConstraint::get_message
0000s0sMoose::Meta::TypeConstraint::::is_a_type_ofMoose::Meta::TypeConstraint::is_a_type_of
0000s0sMoose::Meta::TypeConstraint::::is_subtype_ofMoose::Meta::TypeConstraint::is_subtype_of
0000s0sMoose::Meta::TypeConstraint::::parentsMoose::Meta::TypeConstraint::parents
0000s0sMoose::Meta::TypeConstraint::::validateMoose::Meta::TypeConstraint::validate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::TypeConstraint;
3
4322µs222µs
# spent 19µs (15+4) within Moose::Meta::TypeConstraint::BEGIN@4 which was called # once (15µs+4µs) by Moose::BEGIN@19 at line 4
use strict;
# spent 19µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4 # spent 4µs making 1 call to strict::import
5320µs230µs
# spent 19µs (8+11) within Moose::Meta::TypeConstraint::BEGIN@5 which was called # once (8µs+11µs) by Moose::BEGIN@19 at line 5
use warnings;
# spent 19µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5 # spent 11µs making 1 call to warnings::import
63139µs212.6ms
# spent 12.5ms (12.2+249µs) within Moose::Meta::TypeConstraint::BEGIN@6 which was called # once (12.2ms+249µs) by Moose::BEGIN@19 at line 6
use metaclass;
# spent 12.5ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6 # spent 141µs making 1 call to metaclass::import
7
874186µs7495µs
# spent 52µs (11+41) within Moose::Meta::TypeConstraint::BEGIN@8 which was called # once (11µs+41µs) by Moose::BEGIN@19 at line 9 # spent 312µs (218+95) within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm:8] which was called 74 times, avg 4µs/call: # 23 times (74µs+31µs) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 5µs/call # 17 times (55µs+24µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 217 of Moose/Util/TypeConstraints.pm, avg 5µs/call # 17 times (45µs+20µs) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 203 of Moose/Util/TypeConstraints.pm, avg 4µs/call # 17 times (44µs+19µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 4µs/call
use overload '""' => sub { shift->name }, # stringify to tc name
# spent 95µs making 74 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call
9327µs293µs fallback => 1;
# spent 52µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8 # spent 41µs making 1 call to overload::import
10
11326µs278µs
# spent 43µs (8+35) within Moose::Meta::TypeConstraint::BEGIN@11 which was called # once (8µs+35µs) by Moose::BEGIN@19 at line 11
use Scalar::Util qw(blessed refaddr);
# spent 43µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 35µs making 1 call to Exporter::import
12325µs256µs
# spent 32µs (7+24) within Moose::Meta::TypeConstraint::BEGIN@12 which was called # once (7µs+24µs) by Moose::BEGIN@19 at line 12
use Sub::Name qw(subname);
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 24µs making 1 call to Exporter::import
13
1431.08ms2114µs
# spent 61µs (7+53) within Moose::Meta::TypeConstraint::BEGIN@14 which was called # once (7µs+53µs) by Moose::BEGIN@19 at line 14
use base qw(Class::MOP::Object);
# spent 61µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 53µs making 1 call to base::import
15
161700nsour $VERSION = '0.98';
17114µs$VERSION = eval $VERSION;
181300nsour $AUTHORITY = 'cpan:STEVAN';
19
2014µs2439µs__PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
# spent 422µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 18µs making 1 call to Moose::Meta::TypeConstraint::meta
2112µs2402µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 391µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
22 reader => 'parent',
23 predicate => 'has_parent',
24));
25
2611µsmy $null_constraint = sub { 1 };
27__PACKAGE__->meta->add_attribute('constraint' => (
28 reader => 'constraint',
29 writer => '_set_constraint',
3029µs
# spent 5µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint.pm:30] which was called 2 times, avg 2µs/call: # once (3µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 35 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm # once (2µs+0s) by Moose::Meta::TypeConstraint::_new at line 26 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm
default => sub { $null_constraint }
3114µs2421µs));
# spent 410µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
3212µs2407µs__PACKAGE__->meta->add_attribute('message' => (
# spent 396µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
33 accessor => 'message',
34 predicate => 'has_message'
35));
3612µs2388µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 378µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
37 accessor => 'coercion',
38 predicate => 'has_coercion'
39));
40
4112µs2422µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 412µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
42 init_arg => 'optimized',
43 accessor => 'hand_optimized_type_constraint',
44 predicate => 'has_hand_optimized_type_constraint',
45));
46
47sub parents {
48 my $self;
49 $self->parent;
50}
51
52# private accessors
53
5412µs2388µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 377µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
55 accessor => '_compiled_type_constraint',
56 predicate => '_has_compiled_type_constraint'
57));
5812µs2280µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 269µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta
59 accessor => '_package_defined_in'
60));
61
62
# spent 1.44ms (362µs+1.08) within Moose::Meta::TypeConstraint::new which was called 22 times, avg 66µs/call: # 17 times (257µs+728µs) by Moose::Meta::TypeConstraint::create_child_type at line 298, avg 58µs/call # once (29µs+116µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 533 of Moose/Util/TypeConstraints.pm # once (26µs+106µs) by Moose::Meta::Attribute::BEGIN@18 at line 731 of Moose/Util/TypeConstraints.pm # once (15µs+78µs) by Moose::Meta::Attribute::BEGIN@18 at line 790 of Moose/Util/TypeConstraints.pm # once (21µs+28µs) by Moose::Meta::Attribute::BEGIN@18 at line 752 of Moose/Util/TypeConstraints.pm # once (14µs+26µs) by Moose::Meta::Attribute::BEGIN@18 at line 773 of Moose/Util/TypeConstraints.pm
sub new {
63225µs my $class = shift;
642248µs my ($first, @rest) = @_;
652241µs my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
662213µs $args{name} = $args{name} ? "$args{name}" : "__ANON__";
67
682254µs22357µs my $self = $class->_new(%args);
# spent 250µs making 18 calls to Moose::Meta::TypeConstraint::_new, avg 14µs/call # spent 107µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 27µs/call
692258µs44726µs $self->compile_type_constraint()
# spent 690µs making 22 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 31µs/call # spent 36µs making 22 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call
70 unless $self->_has_compiled_type_constraint;
712275µs return $self;
72}
73
74
75
76sub coerce {
77 my $self = shift;
78
79 my $coercion = $self->coercion;
80
81 unless ($coercion) {
82 require Moose;
83 Moose->throw_error("Cannot coerce without a type coercion");
84 }
85
86 return $_[0] if $self->check($_[0]);
87
88 return $coercion->coerce(@_);
89}
90
91sub check {
92 my ($self, @args) = @_;
93 my $constraint_subref = $self->_compiled_type_constraint;
94 return $constraint_subref->(@args) ? 1 : undef;
95}
96
97sub validate {
98 my ($self, $value) = @_;
99 if ($self->_compiled_type_constraint->($value)) {
100 return undef;
101 }
102 else {
103 $self->get_message($value);
104 }
105}
106
107sub assert_valid {
108 my ($self, $value) = @_;
109
110 my $error = $self->validate($value);
111 return 1 if ! defined $error;
112
113 require Moose;
114 Moose->throw_error($error);
115}
116
117sub get_message {
118 my ($self, $value) = @_;
119 if (my $msg = $self->message) {
120 local $_ = $value;
121 return $msg->($value);
122 }
123 else {
124 $value = (defined $value ? overload::StrVal($value) : 'undef');
125 return "Validation failed for '" . $self->name . "' failed with value $value";
126 }
127}
128
129## type predicates ...
130
131sub equals {
132 my ( $self, $type_or_name ) = @_;
133
134 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
135
136 return 1 if refaddr($self) == refaddr($other);
137
138 if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) {
139 return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint;
140 }
141
142 return unless $self->constraint == $other->constraint;
143
144 if ( $self->has_parent ) {
145 return unless $other->has_parent;
146 return unless $self->parent->equals( $other->parent );
147 } else {
148 return if $other->has_parent;
149 }
150
151 return 1;
152}
153
154sub is_a_type_of {
155 my ($self, $type_or_name) = @_;
156
157 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
158
159 ($self->equals($type) || $self->is_subtype_of($type));
160}
161
162sub is_subtype_of {
163 my ($self, $type_or_name) = @_;
164
165 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
166
167 my $current = $self;
168
169 while (my $parent = $current->parent) {
170 return 1 if $parent->equals($type);
171 $current = $parent;
172 }
173
174 return 0;
175}
176
177## compiling the type constraint
178
179
# spent 730µs (123+607) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 23 times, avg 32µs/call: # 22 times (110µs+579µs) by Moose::Meta::TypeConstraint::new at line 69, avg 31µs/call # once (13µs+27µs) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm
sub compile_type_constraint {
180234µs my $self = shift;
1812389µs46606µs $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 560µs making 23 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 24µs/call # spent 46µs making 23 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call
182}
183
184## type compilers ...
185
186
# spent 560µs (168+392) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 23 times, avg 24µs/call: # 23 times (168µs+392µs) by Moose::Meta::TypeConstraint::compile_type_constraint at line 181, avg 24µs/call
sub _actually_compile_type_constraint {
187233µs my $self = shift;
188
1892372µs40120µs return $self->_compile_hand_optimized_type_constraint
# spent 91µs making 17 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 5µs/call # spent 29µs making 23 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
190 if $self->has_hand_optimized_type_constraint;
191
19269µs69µs my $check = $self->constraint;
# spent 9µs making 6 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
19361µs unless ( defined $check ) {
194 require Moose;
195 Moose->throw_error( "Could not compile type constraint '"
196 . $self->name
197 . "' because no constraint check" );
198 }
199
200625µs11246µs return $self->_compile_subtype($check)
# spent 238µs making 5 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 48µs/call # spent 8µs making 6 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
201 if $self->has_parent;
202
20315µs117µs return $self->_compile_type($check);
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::_compile_type
204}
205
206
# spent 91µs (68+23) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 17 times, avg 5µs/call: # 17 times (68µs+23µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 189, avg 5µs/call
sub _compile_hand_optimized_type_constraint {
207173µs my $self = shift;
208
2091718µs1724µs my $type_constraint = $self->hand_optimized_type_constraint;
# spent 24µs making 17 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 1µs/call
210
211174µs unless ( ref $type_constraint ) {
212 require Moose;
213 Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference");
214 Moose->throw_error("Hand optimized type constraint is not a code reference");
215 }
216
2171738µs return $type_constraint;
218}
219
220
# spent 238µs (133+105) within Moose::Meta::TypeConstraint::_compile_subtype which was called 5 times, avg 48µs/call: # 5 times (133µs+105µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 200, avg 48µs/call
sub _compile_subtype {
22152µs my ($self, $check) = @_;
222
223 # gather all the parent constraintss in order
2245700ns my @parents;
2255600ns my $optimized_parent;
226510µs566µs foreach my $parent ($self->_collect_all_parents) {
# spent 66µs making 5 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 13µs/call
227 # if a parent is optimized, the optimized constraint already includes
228 # all of its parents tcs, so we can break the loop
229914µs911µs if ($parent->has_hand_optimized_type_constraint) {
# spent 11µs making 9 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
230 push @parents => $optimized_parent = $parent->hand_optimized_type_constraint;
231 last;
232 }
233 else {
23499µs910µs push @parents => $parent->constraint;
# spent 10µs making 9 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
235 }
236 }
237
23858µs @parents = grep { $_ != $null_constraint } reverse @parents;
239
24053µs unless ( @parents ) {
241 return $self->_compile_type($check);
242 } elsif( $optimized_parent and @parents == 1 ) {
243 # the case of just one optimized parent is optimized to prevent
244 # looping and the unnecessary localization
245 if ( $check == $null_constraint ) {
246 return $optimized_parent;
247 } else {
248 return subname($self->name, sub {
249 return undef unless $optimized_parent->($_[0]);
250 my (@args) = @_;
251 local $_ = $args[0];
252 $check->(@args);
253 });
254 }
255 } else {
256 # general case, check all the constraints, from the first parent to ourselves
25753µs my @checks = @parents;
25852µs push @checks, $check if $check != $null_constraint;
259 return subname($self->name => sub {
260 my (@args) = @_;
261 local $_ = $args[0];
262 foreach my $check (@checks) {
263 return undef unless $check->(@args);
264 }
265 return 1;
266552µs1017µs });
# spent 10µs making 5 calls to Sub::Name::subname, avg 2µs/call # spent 7µs making 5 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call
267 }
268}
269
270
# spent 17µs (13+4) within Moose::Meta::TypeConstraint::_compile_type which was called # once (13µs+4µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 203
sub _compile_type {
27111µs my ($self, $check) = @_;
272
2731500ns return $check if $check == $null_constraint; # Item, Any
274
275 return subname($self->name => sub {
276 my (@args) = @_;
277 local $_ = $args[0];
278 $check->(@args);
279112µs24µs });
# spent 2µs making 1 call to Moose::Meta::TypeConstraint::name # spent 2µs making 1 call to Sub::Name::subname
280}
281
282## other utils ...
283
284
# spent 66µs (49+17) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 5 times, avg 13µs/call: # 5 times (49µs+17µs) by Moose::Meta::TypeConstraint::_compile_subtype at line 226, avg 13µs/call
sub _collect_all_parents {
28551µs my $self = shift;
2865300ns my @parents;
28757µs58µs my $current = $self->parent;
# spent 8µs making 5 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call
28852µs while (defined $current) {
28992µs push @parents => $current;
290910µs910µs $current = $current->parent;
# spent 10µs making 9 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
291 }
292511µs return @parents;
293}
294
295
# spent 1.09ms (105µs+985µs) within Moose::Meta::TypeConstraint::create_child_type which was called 17 times, avg 64µs/call: # 17 times (105µs+985µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 64µs/call
sub create_child_type {
2961729µs my ($self, %opts) = @_;
297176µs my $class = ref $self;
2981764µs17985µs return $class->new(%opts, parent => $self);
# spent 985µs making 17 calls to Moose::Meta::TypeConstraint::new, avg 58µs/call
299}
300
301126µs1;
302
303__END__
304
305=pod
306
307=head1 NAME
308
309Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
310
311=head1 DESCRIPTION
312
313This class represents a single type constraint. Moose's built-in type
314constraints, as well as constraints you define, are all stored in a
315L<Moose::Meta::TypeConstraint::Registry> object as objects of this
316class.
317
318=head1 INHERITANCE
319
320C<Moose::Meta::TypeConstraint> is a subclass of L<Class::MOP::Object>.
321
322=head1 METHODS
323
324=over 4
325
326=item B<< Moose::Meta::TypeConstraint->new(%options) >>
327
328This creates a new type constraint based on the provided C<%options>:
329
330=over 8
331
332=item * name
333
334The constraint name. If a name is not provided, it will be set to
335"__ANON__".
336
337=item * parent
338
339A C<Moose::Meta::TypeConstraint> object which is the parent type for
340the type being created. This is optional.
341
342=item * constraint
343
344This is the subroutine reference that implements the actual constraint
345check. This defaults to a subroutine which always returns true.
346
347=item * message
348
349A subroutine reference which is used to generate an error message when
350the constraint fails. This is optional.
351
352=item * coercion
353
354A L<Moose::Meta::TypeCoercion> object representing the coercions to
355the type. This is optional.
356
357=item * optimized
358
359This is a variant of the C<constraint> parameter that is somehow
360optimized. Typically, this means incorporating both the type's
361constraint and all of its parents' constraints into a single
362subroutine reference.
363
364=back
365
366=item B<< $constraint->equals($type_name_or_object) >>
367
368Returns true if the supplied name or type object is the same as the
369current type.
370
371=item B<< $constraint->is_subtype_of($type_name_or_object) >>
372
373Returns true if the supplied name or type object is a parent of the
374current type.
375
376=item B<< $constraint->is_a_type_of($type_name_or_object) >>
377
378Returns true if the given type is the same as the current type, or is
379a parent of the current type. This is a shortcut for checking
380C<equals> and C<is_subtype_of>.
381
382=item B<< $constraint->coerce($value) >>
383
384This will attempt to coerce the value to the type. If the type does
385have any defined coercions this will throw an error.
386
387=item B<< $constraint->check($value) >>
388
389Returns true if the given value passes the constraint for the type.
390
391=item B<< $constraint->validate($value) >>
392
393This is similar to C<check>. However, if the type I<is valid> then the
394method returns an explicit C<undef>. If the type is not valid, we call
395C<< $self->get_message($value) >> internally to generate an error
396message.
397
398=item B<< $constraint->assert_valid($value) >>
399
400Like C<check> and C<validate>, this method checks whether C<$value> is
401valid under the constraint. If it is, it will return true. If it is not,
402an exception will be thrown with the results of
403C<< $self->get_message($value) >>.
404
405=item B<< $constraint->name >>
406
407Returns the type's name, as provided to the constructor.
408
409=item B<< $constraint->parent >>
410
411Returns the type's parent, as provided to the constructor, if any.
412
413=item B<< $constraint->has_parent >>
414
415Returns true if the type has a parent type.
416
417=item B<< $constraint->parents >>
418
419A synonym for C<parent>. This is useful for polymorphism with types
420that can have more than one parent.
421
422=item B<< $constraint->constraint >>
423
424Returns the type's constraint, as provided to the constructor.
425
426=item B<< $constraint->get_message($value) >>
427
428This generates a method for the given value. If the type does not have
429an explicit message, we generate a default message.
430
431=item B<< $constraint->has_message >>
432
433Returns true if the type has a message.
434
435=item B<< $constraint->message >>
436
437Returns the type's message as a subroutine reference.
438
439=item B<< $constraint->coercion >>
440
441Returns the type's L<Moose::Meta::TypeCoercion> object, if one
442exists.
443
444=item B<< $constraint->has_coercion >>
445
446Returns true if the type has a coercion.
447
448=item B<< $constraint->hand_optimized_type_constraint >>
449
450Returns the type's hand optimized constraint, as provided to the
451constructor via the C<optimized> option.
452
453=item B<< $constraint->has_hand_optimized_type_constraint >>
454
455Returns true if the type has an optimized constraint.
456
457=item B<< $constraint->create_child_type(%options) >>
458
459This returns a new type constraint of the same class using the
460provided C<%options>. The C<parent> option will be the current type.
461
462This method exists so that subclasses of this class can override this
463behavior and change how child types are created.
464
465=back
466
467=head1 BUGS
468
469See L<Moose/BUGS> for details on reporting bugs.
470
471=head1 AUTHOR
472
473Stevan Little E<lt>stevan@iinteractive.comE<gt>
474
475=head1 COPYRIGHT AND LICENSE
476
477Copyright 2006-2010 by Infinity Interactive, Inc.
478
479L<http://www.iinteractive.com>
480
481This library is free software; you can redistribute it and/or modify
482it under the same terms as Perl itself.
483
484=cut