2 package Moose::Meta::TypeConstraint::Registry;
8 use Scalar::Util 'blessed';
11 our $VERSION = '0.55_01';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
15 use base 'Class::MOP::Object';
17 __PACKAGE__->meta->add_attribute('parent_registry' => (
18 reader => 'get_parent_registry',
19 writer => 'set_parent_registry',
20 predicate => 'has_parent_registry',
23 __PACKAGE__->meta->add_attribute('type_constraints' => (
24 reader => 'type_constraints',
30 my $self = $class->_new(@_);
34 sub has_type_constraint {
35 my ($self, $type_name) = @_;
36 exists $self->type_constraints->{$type_name} ? 1 : 0
39 sub get_type_constraint {
40 my ($self, $type_name) = @_;
41 $self->type_constraints->{$type_name}
44 sub add_type_constraint {
45 my ($self, $type) = @_;
46 $self->type_constraints->{$type->name} = $type;
49 sub find_type_constraint {
50 my ($self, $type_name) = @_;
51 return $self->get_type_constraint($type_name)
52 if $self->has_type_constraint($type_name);
53 return $self->get_parent_registry->find_type_constraint($type_name)
54 if $self->has_parent_registry;
67 Moose::Meta::TypeConstraint::Registry - registry for type constraints
71 This module is currently only use internally by L<Moose::Util::TypeConstraints>.
72 It can be used to create your own private type constraint registry as well, but
73 the details of that are currently left as an exercise to the reader. (One hint:
74 You can use the 'parent_registry' feature to connect your private version with the
75 base Moose registry and base Moose types will automagically be found too).
85 =item B<get_parent_registry>
87 =item B<set_parent_registry ($registry)>
89 =item B<has_parent_registry>
91 =item B<type_constraints>
93 =item B<has_type_constraint ($type_name)>
95 =item B<get_type_constraint ($type_name)>
97 =item B<add_type_constraint ($type)>
99 =item B<find_type_constraint ($type_name)>
105 All complex software has bugs lurking in it, and this module is no
106 exception. If you find a bug please either email me, or add the bug
111 Stevan Little E<lt>stevan@iinteractive.comE<gt>
113 =head1 COPYRIGHT AND LICENSE
115 Copyright 2006-2008 by Infinity Interactive, Inc.
117 L<http://www.iinteractive.com>
119 This library is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.