From 30206ad6bb4549832aafb285c7baac62ee7866e1 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 25 Jun 2013 16:09:21 -0400 Subject: 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 --- lib/Class/Refresh.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/Class/Refresh.pm') 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 populates a -- cgit v1.2.3-54-g00ecf