Why calling Module::Refresh->refresh is redirected to Module::Refresh::CODE?
PerlConsole::Console::interpret(/home/perlconsole-0.4/lib/PerlConsole/Console.pm:281):
281: Module::Refresh->refresh;
DB<5> s
Module::Refresh::CODE(0x70a340)(/home/perlconsole-0.4/depends/Module-Refresh-0.16/lib/Module/Refresh.pm:205):
205: *$sym = sub { goto &$code };
Is there anyone here that can explain thi开发者_运维问答s?
UPDATE
It seems to be caused by this block:
BEGIN {
no strict 'refs';
foreach my $sym ( sort keys %{ __PACKAGE__ . '::' } ) {
next
if $sym eq
'VERSION'; # Skip the version sub, inherited from UNIVERSAL
my $code = __PACKAGE__->can($sym) or next;
delete ${ __PACKAGE__ . '::' }{$sym};
*$sym = sub { goto &$code };
}
}
But why? what's the difference??
If you actually had read the comment above that piece of code you would have already known the answer to your question:
# "Anonymize" all our subroutines into unnamed closures; so we can safely
# refresh this very package.
Jesse is doing some heavy wizardry there in order to make the module able to reload itself (while undefing its own public interface before the reload).
精彩评论