package My; print "Loading...\n"; sub Run { print "Running\n" }
If I were to try to load, remove it from the symbol table, and reload it (as done by Module::Refresh::refresh_module):
use My; delete $INC{"My.pm"}; undef &My::Run; # Why do this?! delete $My::{Run}; require My; eval "My::Run()"; My::Run();
Then I'd see output like this:
Question 1: why does the undef statement makes the next require fail?Loading... Loading... Running Undefined subroutine &My::Run called at -e line 1.
I can get around that by simply removing that line:
Then I'd see output like this:use My; delete $INC{"My.pm"}; delete $My::{Run}; require My; eval "My::Run()"; My::Run();
Loading... Loading... Running Running
Now to the interesting part:
use My; <STDIN>; # NEW delete $INC{"My.pm"}; delete $My::{Run}; require My; eval "My::Run()"; My::Run();
During the pause, update My.pm to have a different output message.
Then press enter to continue:
Loading... Loading... Running again Running
One step further, during the pause, remove the Run function and observe:
Loading... Loading... Running again
Question 2: How to reload a module without having to use an eval (like eval "My::Run()")
Thanks,
~Tim
In reply to Refresh a Module by Timka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |