When a caller tries to import a nonexistent type from a combined type lib, give a...
Dave Rolsky [Wed, 25 Nov 2009 22:26:52 +0000 (16:26 -0600)]
lib/MooseX/Types/Combine.pm
t/18_combined_libs.t

index b44a4c8..1e33a08 100644 (file)
@@ -45,7 +45,14 @@ sub import {
     } @type_libs;
 
     my %from;
-    push @{ $from{ $types{ $_ } } }, $_ for @types;
+    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};
+
+        push @{ $from{ $types{$type} } }, $type;
+    }
 
     $_->import({ -into => $caller }, @{ $from{ $_ } })
         for keys %from;
index b8dc630..a7e2529 100644 (file)
@@ -3,8 +3,9 @@ use strict;
 use warnings;
 use FindBin;
 use lib "$FindBin::Bin/lib";   
-use Test::More tests => 4;
+
+use Test::More tests => 5;
+use Test::Exception;
 
 BEGIN { use_ok 'Combined', qw/Foo2Alias MTFNPY NonEmptyStr/ }
 
@@ -16,3 +17,7 @@ ok MTFNPY;
 
 is NonEmptyStr->name, 'TestLibrary2::NonEmptyStr',
     'precedence for conflicting types is correct';
+
+throws_ok { Combined->import('NonExistentType') }
+qr/\Qmain asked for a type (NonExistentType) which is not found in any of the type libraries (TestLibrary TestLibrary2) combined by Combined/,
+'asking for a non-existent type from a combined type library gives a useful error';