move repository to http://github.com/moose/MooseX-Types
[gitmo/MooseX-Types.git] / lib / MooseX / Types / Base.pm
index e7ab791..87906f8 100644 (file)
@@ -1,23 +1,19 @@
 package MooseX::Types::Base;
 use Moose;
 
-=head1 NAME
-
-MooseX::Types::Base - Type library base class
-
-=cut
+# ABSTRACT: Type library base class
 
 use Carp::Clan                      qw( ^MooseX::Types );
 use MooseX::Types::Util             qw( filter_tags );
 use Sub::Exporter                   qw( build_exporter );
 use Moose::Util::TypeConstraints;
 
-use namespace::clean -except => [qw( meta )];
+use namespace::autoclean;
 
 =head1 DESCRIPTION
 
 You normally won't need to interact with this class by yourself. It is
-merely a collection of functionality that type libraries need to 
+merely a collection of functionality that type libraries need to
 interact with moose and the rest of the L<MooseX::Types> module.
 
 =cut
@@ -30,7 +26,7 @@ my $UndefMsg = q{Unable to find type '%s' in library '%s'};
 
 =head2 import
 
-Provides the import mechanism for your library. See 
+Provides the import mechanism for your library. See
 L<MooseX::Types/"LIBRARY USAGE"> for syntax details on this.
 
 =cut
@@ -50,7 +46,7 @@ sub import {
 
     # determine the wrapper, -into is supported for compatibility reasons
     my $wrapper = $options->{ -wrapper } || 'MooseX::Types';
-    $args[0]->{into} = $options->{ -into } 
+    $args[0]->{into} = $options->{ -into }
         if exists $options->{ -into };
 
     my (%ex_spec, %ex_util);
@@ -64,9 +60,9 @@ sub import {
         my $undef_msg = sprintf($UndefMsg, $type_short, $class);
 
         # the type itself
-        push @{ $ex_spec{exports} }, 
+        push @{ $ex_spec{exports} },
             $type_short,
-            sub { 
+            sub {
                 bless $wrapper->type_export_generator($type_short, $type_full),
                     'MooseX::Types::EXPORTED_TYPE_CONSTRAINT';
             };
@@ -88,13 +84,13 @@ sub import {
 
     # create S:E exporter and increase export level unless specified explicitly
     my $exporter = build_exporter \%ex_spec;
-    $options->{into_level}++ 
+    $options->{into_level}++
         unless $options->{into};
 
     # remember requested symbols to determine what helpers to auto-export
-    my %was_requested = 
-        map  { ($_ => 1) } 
-        grep { not ref } 
+    my %was_requested =
+        map  { ($_ => 1) }
+        grep { not ref }
         @args;
 
     # determine which additional symbols (helpers) to export along
@@ -188,14 +184,93 @@ sub type_storage {
     }
 }
 
-=head1 SEE ALSO
+=head2 registered_class_types
 
-L<MooseX::Types::Moose>
+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
 
-=head1 AUTHOR AND COPYRIGHT
+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};
+}
 
-Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
-the C<#moose> cabal on C<irc.perl.org>.
+=head1 SEE ALSO
+
+L<MooseX::Types::Moose>
 
 =head1 LICENSE