2 package Moose::Meta::TypeConstraint;
8 use Sub::Name 'subname';
11 our $VERSION = '0.01';
13 my %TYPE_CONSTRAINT_REGISTRY;
15 __PACKAGE__->meta->add_attribute('name' => (reader => 'name' ));
16 __PACKAGE__->meta->add_attribute('parent' => (reader => 'parent' ));
17 __PACKAGE__->meta->add_attribute('constraint' => (reader => 'constraint'));
20 __PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
21 accessor => '_compiled_type_constraint'
24 __PACKAGE__->meta->add_attribute('coercion_code' => (
25 reader => 'coercion_code',
26 writer => 'set_coercion_code',
27 predicate => 'has_coercion'
32 my $self = $class->meta->new_object(@_);
33 $self->compile_type_constraint();
37 sub compile_type_constraint () {
39 my $check = $self->constraint;
41 || confess "Could not compile type constraint '" . $self->name . "' because no constraint check";
42 my $parent = $self->parent;
43 if (defined $parent) {
44 $parent = $parent->_compiled_type_constraint;
45 $self->_compiled_type_constraint(subname $self->name => sub {
47 return undef unless defined $parent->($_[0]) && $check->($_[0]);
52 $self->_compiled_type_constraint(subname $self->name => sub {
54 return undef unless $check->($_[0]);
61 sub constraint_code { (shift)->_compiled_type_constraint }
71 Moose::Meta::TypeConstraint - The Moose Type Constraint metaobject
95 =item B<coercion_code>
97 =item B<set_coercion_code>
99 =item B<constraint_code>
101 =item B<has_coercion>
103 =item B<compile_type_constraint>
109 All complex software has bugs lurking in it, and this module is no
110 exception. If you find a bug please either email me, or add the bug
115 Stevan Little E<lt>stevan@iinteractive.comE<gt>
117 =head1 COPYRIGHT AND LICENSE
119 Copyright 2006 by Infinity Interactive, Inc.
121 L<http://www.iinteractive.com>
123 This library is free software; you can redistribute it and/or modify
124 it under the same terms as Perl itself.