summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoramacleay <a.macleay@gmail.com>2014-01-07 11:52:07 -0500
committeramacleay <a.macleay@gmail.com>2014-01-07 11:52:07 -0500
commit576c62dbe64c582eb94ad60fd4782ab4b3057bf0 (patch)
tree4d77353e1c6429487697bfa04fc867865d707aac
parentf0153f9e0aa32910bef579d7956e59d933108261 (diff)
downloadclass-refresh-576c62dbe64c582eb94ad60fd4782ab4b3057bf0.tar.gz
class-refresh-576c62dbe64c582eb94ad60fd4782ab4b3057bf0.zip
Do not die if last require failed
-rw-r--r--lib/Class/Refresh.pm11
-rw-r--r--t/basic.t12
-rw-r--r--t/data/basic/after/UseFake.pm5
3 files changed, 27 insertions, 1 deletions
diff --git a/lib/Class/Refresh.pm b/lib/Class/Refresh.pm
index eb1dda8..320490d 100644
--- a/lib/Class/Refresh.pm
+++ b/lib/Class/Refresh.pm
@@ -187,11 +187,20 @@ sub load_module {
my ($mod) = @_;
$mod = $class->_file_to_mod($mod);
+ my $file = $class->_mod_to_file($mod);
+ my $last_require_failed = exists $INC{$file} && !defined $INC{$file};
+
try {
Class::Load::load_class($mod);
}
catch {
- die $_;
+ if ($last_require_failed) {
+ # This file failed to load previously.
+ # Presumably that error has already been caught, so that's fine
+ }
+ else {
+ die $_;
+ }
}
finally {
$class->_update_cache_for($mod);
diff --git a/t/basic.t b/t/basic.t
index 9b7eb8a..93e0772 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -2,8 +2,10 @@
use strict;
use warnings;
use Test::More;
+use Test::Fatal;
use lib 't/lib';
use Test::Class::Refresh;
+use Try::Tiny;
use Class::Refresh;
@@ -37,4 +39,14 @@ is(eval '$Foo::FOO', 10, "package global exists with new value");
ok(!defined(eval '$Foo::BAR'), "other package global doesn't exist");
is(eval '$Foo::BAZ', 30, "third package global exists");
+try { require UseFake } catch { "We expect this to fail, that's alright and happens sometimes" };
+Class::Refresh->refresh;
+ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists");
+ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load");
+
+# Now do the same thing to validate that there's no error in repopulating %CACHE
+isnt(exception{ Class::Refresh->refresh }, "Second refresh is not an error");
+ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists: second attempt");
+ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load: second attempt");
+
done_testing;
diff --git a/t/data/basic/after/UseFake.pm b/t/data/basic/after/UseFake.pm
new file mode 100644
index 0000000..efc0d3e
--- /dev/null
+++ b/t/data/basic/after/UseFake.pm
@@ -0,0 +1,5 @@
+package RequiresFake;
+
+use Fake;
+
+1;