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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.