I'm currently experimenting with rebooting the module. The goal that I hope to achieve is the ability to change something in a specific routine in a module file, and then reload this module using new definitions.
I am currently modifying the print statement in the test routine to print βthis is some other textβ after waiting for the source routine to execute and before the module is reloaded.
However, what I am currently receiving is this message:
Subroutine test redefined at /Test/testmodule.pm line 9.
This is exactly what I want, but the conclusion is as follows.
this is some text
Subroutine test redefined at /Test/testmodule.pm line 9.
this is some text
I hope that when the module is reloaded and it understands that the subroutine has been redefined, the next time that it runs the test subroutine, it will refer to the new definition, not the old one.
I looked through previous questions about reloading modules, but the answers were like loop hangs (package A uses B and B uses A) or namespace conflicts in packages, but this is not a problem, I want to redefine the subroutine and use the new definition.
source code: main.pl
#!/usr/bin/perl use strict; use warnings; use Module::Reload::Selective; use Test::testmodule; while(1) { test(); #run module define subroutine sleep(5); #stop terminal from being flooded too quickly #Ensure that the module is reloaded $Module::Reload::Selective::Options->{SearchProgramDir} = 1; $Module::Reload::Selective::Options->{ReloadOnlyIfEnvVarsSet} = 0; Module::Reload::Selective->reload(qw(Test::testmodule)); #reload! }
source code: testmodule.pm (in ./Test/ relative to main.pl)
Any pointers or links to textbooks would be brilliant. In fact, if the answer is not incredibly simple without telling me that the answer will directly allow me to read your proposed material and gain a general understanding.
All the necessary CPAN modules have been installed, and I can confirm that testmodule.pm is successfully written after the change.
OS : Scientific Linux CERN 6, kernel version 2.6.32-131.4.1.el6.x86_64
Perl : v5.10.1 (*) for x86_64-linux-thread-multi
Thank you very much in advance,
Owen.