summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Reddick <michael.reddick@gmail.com>2013-06-20 16:28:33 -0500
committerMichael Reddick <michael.reddick@gmail.com>2013-06-20 16:28:33 -0500
commit18998e8fbc417814adaeec3b21e722e068a8f807 (patch)
tree2c2e61f321360bcedcf77b0bf7d8efee1abfcd19
parentaac3b20f3546338a8bcda64d5e4a758673734b87 (diff)
downloadclass-refresh-18998e8fbc417814adaeec3b21e722e068a8f807.tar.gz
class-refresh-18998e8fbc417814adaeec3b21e722e068a8f807.zip
Wrap load_class in a try { } block.
This fixes the case where a module was loaded then attempted to be loaded but with a failure. Previously it wouldn't refresh itself anymore.
-rw-r--r--lib/Class/Refresh.pm19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/Class/Refresh.pm b/lib/Class/Refresh.pm
index 62a64cd..54798d5 100644
--- a/lib/Class/Refresh.pm
+++ b/lib/Class/Refresh.pm
@@ -5,6 +5,7 @@ use warnings;
use Class::Unload;
use Class::Load;
+use Try::Tiny;
=head1 SYNOPSIS
@@ -74,6 +75,13 @@ sub modified_modules {
my $class = shift;
my @ret;
+ for my $file (keys %CACHE) {
+ # refresh files that are in our
+ # %CACHE but not in %INC
+ push @ret, $class->_file_to_mod($file)
+ if (!$INC{$file});
+ }
+
for my $file (keys %INC) {
if (exists $CACHE{$file}) {
push @ret, $class->_file_to_mod($file)
@@ -140,7 +148,13 @@ sub load_module {
my ($mod) = @_;
$mod = $class->_file_to_mod($mod);
- Class::Load::load_class($mod);
+ try {
+ Class::Load::load_class($mod);
+ }
+ catch {
+ warn $_;
+ };
+
$class->_update_cache_for($mod);
}
@@ -187,7 +201,6 @@ sub _update_cache_for {
my $class = shift;
my ($file) = @_;
$file = $class->_mod_to_file($file);
-
$CACHE{$file} = $class->_mtime($file);
}
@@ -203,7 +216,7 @@ sub _mtime {
my $class = shift;
my ($file) = @_;
$file = $class->_mod_to_file($file);
-
+ return 1 if !$INC{$file};
return join ' ', (stat($INC{$file}))[1, 7, 9];
}