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=0fdaa691d6c0f83e75757d908c9e32355468365b;hp=a0fbe348dde2728d7cb9c4908d6d5d2c240b908b;hb=6a1db9c7c89f006f6231aa64a9629dd1de7c5a15;hpb=ca9d7442ae7d1b9268a668d7103e0c9d7aef1dde diff --git a/lib/MooseX/Types/Combine.pm b/lib/MooseX/Types/Combine.pm index a0fbe34..0fdaa69 100644 --- a/lib/MooseX/Types/Combine.pm +++ b/lib/MooseX/Types/Combine.pm @@ -5,6 +5,7 @@ MooseX::Types::Combine - Combine type libraries for exporting =cut package MooseX::Types::Combine; +our $VERSION = "0.26"; use strict; use warnings; @@ -14,7 +15,7 @@ use Class::MOP (); package CombinedTypeLib; - use base 'MooseX::Types::Combined'; + use base 'MooseX::Types::Combine'; __PACKAGE__->provide_types_from(qw/TypeLib1 TypeLib2/); @@ -35,16 +36,20 @@ 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; - 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,15 +69,50 @@ 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 +=head1 AUTHOR + +See L. + =head1 LICENSE This program is free software; you can redistribute it and/or modify