From: Shawn M Moore Date: Sat, 16 May 2009 10:12:44 +0000 (-0400) Subject: If we M'Ex/also a module that isn't loaded, hint that to the user X-Git-Tag: 0.80~84 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ba1a3c2f06ecc94ecad6a82580fb5654e01ada25;p=gitmo%2FMoose.git If we M'Ex/also a module that isn't loaded, hint that to the user --- diff --git a/Changes b/Changes index 94c28a6..75d6a88 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,10 @@ for, noteworthy changes. resilient in the face of global destruction's random garbage collection order. + * Moose::Exporter + - If you "also" a module that isn't loaded, the error message + now acknowledges that (Sartak) + 0.78 Tue, May 12, 2009 * Moose::Cookbook::FAQ and Moose::Cookbook::WTF - Merged these documents into what is now Moose::Manual::FAQ diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index de058f1..375b2d8 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -76,8 +76,13 @@ sub build_import_methods { sub _follow_also_real { my $exporting_package = shift; - die "Package in also ($exporting_package) does not seem to use Moose::Exporter" - unless exists $EXPORT_SPEC{$exporting_package}; + if (!exists $EXPORT_SPEC{$exporting_package}) { + my $loaded = Class::MOP::is_class_loaded($exporting_package); + + die "Package in also ($exporting_package) does not seem to " + . "use Moose::Exporter" + . ($loaded ? "" : " (is it loaded?)"); + } my $also = $EXPORT_SPEC{$exporting_package}{also}; diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index f8d82a2..bb474fd 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -8,7 +8,7 @@ use Test::Exception; BEGIN { eval "use Test::Output;"; plan skip_all => "Test::Output is required for this test" if $@; - plan tests => 45; + plan tests => 47; } @@ -216,7 +216,7 @@ BEGIN { } { - package MooseX::CircularAlso; + package MooseX::NoAlso; use Moose (); @@ -231,7 +231,28 @@ BEGIN { ::like( $@, - qr/\QPackage in also (NoSuchThing) does not seem to use Moose::Exporter/, + qr/\QPackage in also (NoSuchThing) does not seem to use Moose::Exporter (is it loaded?) at /, + 'got the expected error from a reference in also to a package which is not loaded' + ); +} + +{ + package MooseX::NotExporter; + + use Moose (); + + ::dies_ok( + sub { + Moose::Exporter->setup_import_methods( + also => [ 'Moose::Meta::Method' ], + ); + }, + 'a package which does not use Moose::Exporter in also dies with an error' + ); + + ::like( + $@, + qr/\QPackage in also (Moose::Meta::Method) does not seem to use Moose::Exporter at /, 'got the expected error from a reference in also to a package which does not use Moose::Exporter' ); }