http://qs1969.pair.com?node_id=316086

JPaul has asked for the wisdom of the Perl Monks concerning the following question:

Greetings all;
I have another stoater here, that I'm sure some wise monk will be able to point out what exactly is going on - but truly has me confused.
First of all, I only recently discovered perl could literally reload modules on the fly. This is why I love perl. Not only is this so immensely cool - but perl makes it so easy. I firmly believe this is a sign of a superior language. But enough ass kissing.

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"); }
And, as you'll see soon enough, foo.pm reloads without any complaints, time and time again. However reload.pm leaves us with an undesireable "Subroutine redefined" warning.
All I want is for the warning to go away.
I could, simply, not use warnings at all - but I'd much rather find a way around this, if I can. Turning warnings off doesn't work either, I believe also related to scope.

-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Update: Apparently my terminology is guff. Not lexical scope, but dynamic.