package MooseX::Types::Base;
use Moose;
-=head1 NAME
+# ABSTRACT: Type library base class
-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 );
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
=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
# 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);
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';
};
# 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
}
}
-=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