My reload module is amply stolen from Apache::StatINC, as suggested here. This works perfectly for loading modules like it should - EXCEPT when it reloads itself. I suspect changing the package namespace on the function while it is running perhaps cocks up the lexical scope for the local - but I'm not entirely positive.
package foo; use strict; use warnings; sub bar { print "Works\n"; } 1; package reload; use strict; use warnings; sub reload { my ($PM) = @_; delete $INC{"$PM.pm"}; local $^W = 0; eval("require $PM;"); } 1; #Script #!/usr/bin/perl -w use strict; use reload; while(<STDIN>) print "Hit Enter.\n"; &reload::reload("foo"); &foo::bar(); &reload::reload("reload"); }
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --
Update: Apparently my terminology is guff. Not lexical scope, but dynamic.
In reply to Reloading modules- suppressing warnings works sometimes? by JPaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |