little better error message there
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Registry.pm
CommitLineData
22aed3c0 1
2package Moose::Meta::TypeConstraint::Registry;
3
4use strict;
5use warnings;
6use metaclass;
7
8use Scalar::Util 'blessed';
9use Carp 'confess';
10
11our $VERSION = '0.01';
12our $AUTHORITY = 'cpan:STEVAN';
13
14use base 'Class::MOP::Object';
15
183ba44e 16__PACKAGE__->meta->add_attribute('parent_registry' => (
17 reader => 'get_parent_registry',
18 writer => 'set_parent_registry',
19 predicate => 'has_parent_registry',
20));
21
22aed3c0 22__PACKAGE__->meta->add_attribute('type_constraints' => (
23 reader => 'type_constraints',
24 default => sub { {} }
25));
26
27sub new {
28 my $class = shift;
29 my $self = $class->meta->new_object(@_);
30 return $self;
31}
32
33sub has_type_constraint {
34 my ($self, $type_name) = @_;
35 exists $self->type_constraints->{$type_name} ? 1 : 0
36}
37
38sub get_type_constraint {
39 my ($self, $type_name) = @_;
40 $self->type_constraints->{$type_name}
41}
42
43sub add_type_constraint {
44 my ($self, $type) = @_;
45 $self->type_constraints->{$type->name} = $type;
46}
47
183ba44e 48sub 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;
54 return;
55}
56
22aed3c0 571;
58
59__END__
60
61
62=pod
63
64=head1 NAME
65
66Moose::Meta::TypeConstraint::Registry
67
68=head1 DESCRIPTION
69
70=head1 METHODS
71
72=over 4
73
74=item B<meta>
75
76=item B<new>
77
183ba44e 78=item B<get_parent_registry>
79
80=item B<set_parent_registry ($registry)>
81
82=item B<has_parent_registry>
83
22aed3c0 84=item B<type_constraints>
85
183ba44e 86=item B<has_type_constraint ($type_name)>
87
88=item B<get_type_constraint ($type_name)>
22aed3c0 89
183ba44e 90=item B<add_type_constraint ($type)>
22aed3c0 91
183ba44e 92=item B<find_type_constraint ($type_name)>
22aed3c0 93
94=back
95
96=head1 BUGS
97
98All complex software has bugs lurking in it, and this module is no
99exception. If you find a bug please either email me, or add the bug
100to cpan-RT.
101
102=head1 AUTHOR
103
104Stevan Little E<lt>stevan@iinteractive.comE<gt>
105
106=head1 COPYRIGHT AND LICENSE
107
108Copyright 2006, 2007 by Infinity Interactive, Inc.
109
110L<http://www.iinteractive.com>
111
112This library is free software; you can redistribute it and/or modify
113it under the same terms as Perl itself.
114
115=cut