X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCombine.pm;h=0fdaa691d6c0f83e75757d908c9e32355468365b;hb=6a1db9c7c89f006f6231aa64a9629dd1de7c5a15;hp=1e33a08c54772e54af04a334bbeb0f4f09cd6c8a;hpb=bd47cf6420c3cc9b129164d6d0fcb7985a951ae1;p=gitmo%2FMooseX-Types.git diff --git a/lib/MooseX/Types/Combine.pm b/lib/MooseX/Types/Combine.pm index 1e33a08..0fdaa69 100644 --- a/lib/MooseX/Types/Combine.pm +++ b/lib/MooseX/Types/Combine.pm @@ -5,7 +5,7 @@ MooseX::Types::Combine - Combine type libraries for exporting =cut package MooseX::Types::Combine; -our $VERSION = "0.20"; +our $VERSION = "0.26"; use strict; use warnings; @@ -36,20 +36,17 @@ sub import { my ($class, @types) = @_; my $caller = caller; - my @type_libs = $class->provide_types_from; - Class::MOP::load_class($_) for @type_libs; - - my %types = map { - my $lib = $_; - map +($_ => $lib), $lib->type_names - } @type_libs; + my %types = $class->_provided_types; my %from; for my $type (@types) { - die - "$caller asked for a type ($type) which is not found in any of the" - . " type libraries (@type_libs) combined by $class\n" - unless $types{$type}; + 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; } @@ -72,11 +69,42 @@ 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; } +sub _check_type_lib { + my ($class, $lib) = @_; + + 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" } }; + + %$types = %types + if keys %types; + + %$types; +} + =head1 SEE ALSO L