G'day ainkov,
Welcome to the monastery.
I investigated this for a while. I have some findings but, as yet, no definitive answer. I don't have time to continue this now. I'll post what I have: that may help you, or someone else, towards a resolution; if not, I can continue to look into this tomorrow.
I created MyModule.pm and Importer.pm exactly as you posted them. They remained unchanged throughout all tests. All tests below used modified versions of test.pl.
I initially looked at the %main::MyModule:: stash (without referencing the $main::MyModule::{HASH} key):
$ cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; require 'MyModule.pm'; print Dumper \%main::MyModule::; $ test.pl main::MyModule $VAR1 = { 'BEGIN' => *::MyModule::BEGIN };
So, "main::MyModule", in the output, is not dependent on "my $symtab = *{'main::MyModule::'}{HASH};"; %main::MyModule:: is created with the key $main::MyModule::{BEGIN}. Next I tried the require within an explicit BEGIN block:
$ cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; BEGIN { require 'MyModule.pm'; } print Dumper \%main::MyModule::; $ test.pl MyModule $VAR1 = { 'BEGIN' => *MyModule::BEGIN };
Now we get "MyModule" instead of "main::MyModule"; %main::MyModule::, with just the key $main::MyModule::{BEGIN}, is the same. I repeated both of those tests with "require MyModule;". Without a BEGIN block:
$ cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; require MyModule; print Dumper \%main::MyModule::; $ test.pl MyModule $VAR1 = { 'BEGIN' => *MyModule::BEGIN };
And with a BEGIN block:
$ cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; BEGIN { require MyModule; } print Dumper \%main::MyModule::; $ test.pl MyModule $VAR1 = { 'BEGIN' => *MyModule::BEGIN };
In both of those cases, we have "MyModule" instead of "main::MyModule"; and %main::MyModule::, with just the key $main::MyModule::{BEGIN}, is still present and unchanged. I next looked at "use MyModule;":
$ cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use MyModule; print Dumper \%main::MyModule::; $ test.pl MyModule $VAR1 = { 'BEGIN' => *MyModule::BEGIN, 'import' => *MyModule::import };
Now, %main::MyModule:: has an additional key: $main::MyModule::{import}.
That's where I'll have to leave it for now.
-- Ken
In reply to Re: Strange side effect on 'caller' function result
by kcott
in thread Strange side effect on 'caller' function result
by ainkov
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |