Implement the "eval $VERSION" trick from perlmodstyle so CPAN doesn't
[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
75b95414 11our $VERSION = '0.55_01';
12$VERSION = eval $VERSION;
22aed3c0 13our $AUTHORITY = 'cpan:STEVAN';
14
15use base 'Class::MOP::Object';
16
183ba44e 17__PACKAGE__->meta->add_attribute('parent_registry' => (
18 reader => 'get_parent_registry',
19 writer => 'set_parent_registry',
20 predicate => 'has_parent_registry',
21));
22
22aed3c0 23__PACKAGE__->meta->add_attribute('type_constraints' => (
24 reader => 'type_constraints',
25 default => sub { {} }
26));
27
28sub new {
29 my $class = shift;
0779da92 30 my $self = $class->_new(@_);
22aed3c0 31 return $self;
32}
33
34sub has_type_constraint {
35 my ($self, $type_name) = @_;
36 exists $self->type_constraints->{$type_name} ? 1 : 0
37}
38
39sub get_type_constraint {
40 my ($self, $type_name) = @_;
41 $self->type_constraints->{$type_name}
42}
43
44sub add_type_constraint {
45 my ($self, $type) = @_;
46 $self->type_constraints->{$type->name} = $type;
47}
48
183ba44e 49sub 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;
55 return;
56}
57
22aed3c0 581;
59
60__END__
61
62
63=pod
64
65=head1 NAME
66
a0542df9 67Moose::Meta::TypeConstraint::Registry - registry for type constraints
22aed3c0 68
69=head1 DESCRIPTION
70
a0542df9 71This module is currently only use internally by L<Moose::Util::TypeConstraints>.
72It can be used to create your own private type constraint registry as well, but
73the details of that are currently left as an exercise to the reader. (One hint:
74You can use the 'parent_registry' feature to connect your private version with the
75base Moose registry and base Moose types will automagically be found too).
76
22aed3c0 77=head1 METHODS
78
79=over 4
80
81=item B<meta>
82
83=item B<new>
84
183ba44e 85=item B<get_parent_registry>
86
87=item B<set_parent_registry ($registry)>
88
89=item B<has_parent_registry>
90
22aed3c0 91=item B<type_constraints>
92
183ba44e 93=item B<has_type_constraint ($type_name)>
94
95=item B<get_type_constraint ($type_name)>
22aed3c0 96
183ba44e 97=item B<add_type_constraint ($type)>
22aed3c0 98
183ba44e 99=item B<find_type_constraint ($type_name)>
22aed3c0 100
101=back
102
103=head1 BUGS
104
105All complex software has bugs lurking in it, and this module is no
106exception. If you find a bug please either email me, or add the bug
107to cpan-RT.
108
109=head1 AUTHOR
110
111Stevan Little E<lt>stevan@iinteractive.comE<gt>
112
113=head1 COPYRIGHT AND LICENSE
114
778db3ac 115Copyright 2006-2008 by Infinity Interactive, Inc.
22aed3c0 116
117L<http://www.iinteractive.com>
118
119This library is free software; you can redistribute it and/or modify
120it under the same terms as Perl itself.
121
122=cut