2 package Moose::Meta::TypeConstraint::Registry;
8 use Scalar::Util 'blessed';
11 our $VERSION = '0.01';
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Class::MOP::Object';
16 __PACKAGE__->meta->add_attribute('parent_registry' => (
17 reader => 'get_parent_registry',
18 writer => 'set_parent_registry',
19 predicate => 'has_parent_registry',
22 __PACKAGE__->meta->add_attribute('type_constraints' => (
23 reader => 'type_constraints',
29 my $self = $class->meta->new_object(@_);
33 sub has_type_constraint {
34 my ($self, $type_name) = @_;
35 exists $self->type_constraints->{$type_name} ? 1 : 0
38 sub get_type_constraint {
39 my ($self, $type_name) = @_;
40 $self->type_constraints->{$type_name}
43 sub add_type_constraint {
44 my ($self, $type) = @_;
45 $self->type_constraints->{$type->name} = $type;
48 sub find_type_constraint {
49 my ($self, $type_name) = @_;
50 return $self->get_type_constraint($type_name)
51 if $self->has_type_constraint($type_name);
52 return $self->get_parent_registry->find_type_constraint($type_name)
53 if $self->has_parent_registry;
66 Moose::Meta::TypeConstraint::Registry - registry for type constraints
70 This module is currently only use internally by L<Moose::Util::TypeConstraints>.
71 It can be used to create your own private type constraint registry as well, but
72 the details of that are currently left as an exercise to the reader. (One hint:
73 You can use the 'parent_registry' feature to connect your private version with the
74 base Moose registry and base Moose types will automagically be found too).
84 =item B<get_parent_registry>
86 =item B<set_parent_registry ($registry)>
88 =item B<has_parent_registry>
90 =item B<type_constraints>
92 =item B<has_type_constraint ($type_name)>
94 =item B<get_type_constraint ($type_name)>
96 =item B<add_type_constraint ($type)>
98 =item B<find_type_constraint ($type_name)>
104 All complex software has bugs lurking in it, and this module is no
105 exception. If you find a bug please either email me, or add the bug
110 Stevan Little E<lt>stevan@iinteractive.comE<gt>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2006, 2007 by Infinity Interactive, Inc.
116 L<http://www.iinteractive.com>
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.