Version 0.22
[gitmo/MooseX-Types.git] / lib / MooseX / Types / Base.pm
index 15ba3e4..520273a 100644 (file)
@@ -1,4 +1,5 @@
 package MooseX::Types::Base;
+our $VERSION = "0.22";
 use Moose;
 
 =head1 NAME
@@ -7,7 +8,6 @@ MooseX::Types::Base - Type library base class
 
 =cut
 
-#use Data::Dump                      qw( dump );
 use Carp::Clan                      qw( ^MooseX::Types );
 use MooseX::Types::Util             qw( filter_tags );
 use Sub::Exporter                   qw( build_exporter );
@@ -67,7 +67,10 @@ sub import {
         # the type itself
         push @{ $ex_spec{exports} }, 
             $type_short,
-            sub { $wrapper->type_export_generator($type_short, $type_full) };
+            sub { 
+                bless $wrapper->type_export_generator($type_short, $type_full),
+                    'MooseX::Types::EXPORTED_TYPE_CONSTRAINT';
+            };
 
         # the check helper
         push @{ $ex_spec{exports} },
@@ -186,14 +189,97 @@ sub type_storage {
     }
 }
 
+=head2 registered_class_types
+
+Returns the class types registered within this library. Don't use directly.
+
+=cut
+
+sub registered_class_types {
+    my ($class) = @_;
+
+    {
+        no strict 'refs';
+        return \%{ $class . '::__MOOSEX_TYPELIBRARY_CLASS_TYPES' };
+    }
+}
+
+=head2 register_class_type
+
+Register a C<class_type> for use in this library by class name.
+
+=cut
+
+sub register_class_type {
+    my ($class, $type) = @_;
+
+    croak "Not a class_type"
+        unless $type->isa('Moose::Meta::TypeConstraint::Class');
+
+    $class->registered_class_types->{$type->class} = $type;
+}
+
+=head2 get_registered_class_type
+
+Get a C<class_type> registered in this library by name.
+
+=cut
+
+sub get_registered_class_type {
+    my ($class, $name) = @_;
+
+    $class->registered_class_types->{$name};
+}
+
+=head2 registered_role_types
+
+Returns the role types registered within this library. Don't use directly.
+
+=cut
+
+sub registered_role_types {
+    my ($class) = @_;
+
+    {
+        no strict 'refs';
+        return \%{ $class . '::__MOOSEX_TYPELIBRARY_ROLE_TYPES' };
+    }
+}
+
+=head2 register_role_type
+
+Register a C<role_type> for use in this library by role name.
+
+=cut
+
+sub register_role_type {
+    my ($class, $type) = @_;
+
+    croak "Not a role_type"
+        unless $type->isa('Moose::Meta::TypeConstraint::Role');
+
+    $class->registered_role_types->{$type->role} = $type;
+}
+
+=head2 get_registered_role_type
+
+Get a C<role_type> registered in this library by role name.
+
+=cut
+
+sub get_registered_role_type {
+    my ($class, $name) = @_;
+
+    $class->registered_role_types->{$name};
+}
+
 =head1 SEE ALSO
 
 L<MooseX::Types::Moose>
 
-=head1 AUTHOR AND COPYRIGHT
+=head1 AUTHOR
 
-Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
-the C<#moose> cabal on C<irc.perl.org>.
+See L<MooseX::Types/AUTHOR>.
 
 =head1 LICENSE