diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-06-25 16:09:21 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-06-25 16:09:21 -0400 |
commit | 30206ad6bb4549832aafb285c7baac62ee7866e1 (patch) | |
tree | bd300d686a42a60cd1f1a138bd38f84cc945e0f1 /lib/Class/Refresh.pm | |
parent | 4057cb05c89bc4ba1a561c21e840885ad38975c8 (diff) | |
download | class-refresh-30206ad6bb4549832aafb285c7baac62ee7866e1.tar.gz class-refresh-30206ad6bb4549832aafb285c7baac62ee7866e1.zip |
allow optionally installing a require hook to track module loads
this will be more accurate about when to reload things, but uses a
require hook, which may cause issues with other modules that hook
require in an incorrect way
Diffstat (limited to 'lib/Class/Refresh.pm')
-rw-r--r-- | lib/Class/Refresh.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Class/Refresh.pm b/lib/Class/Refresh.pm index 24569ab..4d3cb2f 100644 --- a/lib/Class/Refresh.pm +++ b/lib/Class/Refresh.pm @@ -51,6 +51,30 @@ this will likely not work. our %CACHE; +sub import { + my $package = shift; + my %opts = @_; + + if ($opts{track_require}) { + require Devel::OverrideGlobalRequire; + require B; + Devel::OverrideGlobalRequire::override_global_require(sub { + my $next = shift; + my ($file) = @_; + + my $ret = $next->(); + + $package->_update_cache_for($file) + # require v5.8.1; + unless ref(\$file) eq 'VSTRING' + # require 5.008001; + || !(B::svref_2object(\$file)->FLAGS & B::SVf_POK()); + + return $ret; + }); + } +} + =method refresh The main entry point to the module. The first call to C<refresh> populates a |