X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types.git;a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCombine.pm;h=43aa79f11f91ea90fc0a3d6313e8c14a893945c3;hp=e16b39afd9f0ca1d9c737e832c7ef49adaf05162;hb=e51f897114e6c350b82b39986858fc614c3ca62d;hpb=e9c8511550b9bf8db3b449154a58f1e3ea3641a7 diff --git a/lib/MooseX/Types/Combine.pm b/lib/MooseX/Types/Combine.pm index e16b39a..43aa79f 100644 --- a/lib/MooseX/Types/Combine.pm +++ b/lib/MooseX/Types/Combine.pm @@ -1,11 +1,7 @@ -=head1 NAME - -MooseX::Types::Combine - Combine type libraries for exporting - -=cut - package MooseX::Types::Combine; +# ABSTRACT: Combine type libraries for exporting + use strict; use warnings; use Class::MOP (); @@ -35,16 +31,26 @@ sub import { my ($class, @types) = @_; my $caller = caller; - my @type_libs = $class->provide_types_from; - Class::MOP::load_class($_) for @type_libs; + my %types = $class->_provided_types; - my %types = map { - my $lib = $_; - map +($_ => $lib), $lib->type_names - } @type_libs; + if ( grep { $_ eq ':all' } @types ) { + $_->import( { -into => $caller }, q{:all} ) + for $class->provide_types_from; + return; + } my %from; - push @{ $from{ $types{ $_ } } }, $_ for @types; + for my $type (@types) { + unless ($types{$type}) { + my @type_libs = $class->provide_types_from; + + die + "$caller asked for a type ($type) which is not found in any of the" + . " type libraries (@type_libs) combined by $class\n"; + } + + push @{ $from{ $types{$type} } }, $type; + } $_->import({ -into => $caller }, @{ $from{ $_ } }) for keys %from; @@ -64,18 +70,45 @@ sub provide_types_from { my $store = do { no strict 'refs'; \@{ "${class}::__MOOSEX_TYPELIBRARY_LIBRARIES" } }; - @$store = @libs if @libs; + if (@libs) { + $class->_check_type_lib($_) for @libs; + @$store = @libs; + + my %types = map { + my $lib = $_; + map +( $_ => $lib ), $lib->type_names + } @libs; + + $class->_provided_types(%types); + } @$store; } -=head1 SEE ALSO +sub _check_type_lib { + my ($class, $lib) = @_; -L + Class::MOP::load_class($lib); + + die "Cannot use $lib in a combined type library, it does not provide any types" + unless $lib->can('type_names'); +} + +sub _provided_types { + my ($class, %types) = @_; + + my $types = + do { no strict 'refs'; \%{ "${class}::__MOOSEX_TYPELIBRARY_TYPES" } }; -=head1 AUTHOR + %$types = %types + if keys %types; -See L. + %$types; +} + +=head1 SEE ALSO + +L =head1 LICENSE