Subject: | use_package_optimistically fails to report a failure in the module itself to load a different module |
If you use use_package_optimistically to attempt to load a module with an error, that error is typically reported, except if the error is due to a failure in that module to load another module. This is because the regex used in use_package_optimistically is too lax. See attached for a fix.
Subject: | upo.patch |
diff -uNr a/lib/Module/Runtime.pm b/lib/Module/Runtime.pm
--- a/lib/Module/Runtime.pm 2012-02-16 15:11:34.000000000 -0500
+++ b/lib/Module/Runtime.pm 2013-06-24 18:24:05.251462576 -0400
@@ -381,8 +381,9 @@
my($name, $version) = @_;
check_module_name($name);
eval { local $SIG{__DIE__}; require_module($name); };
+ my $file = module_notional_filename($name);
die $@ if $@ ne "" &&
- $@ !~ /\ACan't locate .+ at \Q@{[__FILE__]}\E line/s;
+ $@ !~ /\ACan't locate \Q$file\E .+ at \Q@{[__FILE__]}\E line/s;
$name->VERSION($version) if defined $version;
return $name;
}
diff -uNr a/t/upo.t b/t/upo.t
--- a/t/upo.t 2012-02-16 15:11:34.000000000 -0500
+++ b/t/upo.t 2013-06-24 18:23:21.651491626 -0400
@@ -1,7 +1,7 @@
use warnings;
use strict;
-use Test::More tests => 30;
+use Test::More tests => 31;
BEGIN { use_ok "Module::Runtime", qw(use_package_optimistically); }
@@ -87,4 +87,8 @@
ok defined($t::Context::VERSION);
ok $INC{"t/Context.pm"};
+# loads a module which doesn't exist
+test_use_package_optimistically("t::WithDep");
+like $err, qr/Can't locate Dep\.pm in \@INC/;
+
1;
diff -uNr a/t/WithDep.pm b/t/WithDep.pm
--- a/t/WithDep.pm 1969-12-31 19:00:00.000000000 -0500
+++ b/t/WithDep.pm 2013-06-24 18:22:15.438202381 -0400
@@ -0,0 +1 @@
+use Dep;