in reply to Use of typeglob in package import subroutine

That's just the way it works. Yeah, I know, it's weird.

The typeglob assignment is usually what you want in exporters anyway, as it creates an alias between the two variables, rather than just copying data from one to the other.

Also, \${"${package}::pet"} is probably better written as \$pet.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: Use of typeglob in package import subroutine
by GG1985 (Initiate) on Apr 29, 2014 at 18:27 UTC
    Taking the points from both replies, I summarize the following given below.

    In the example 1,

    The variable $main::pet is never declared. But, the typeglob assignment made it as an alias for $Zoo:pet which has indeed been declared with our. So 'use strict' didn't throw error since somehow $main::pet got indirectly declared.


    In the example 2,

    Here too, the variable $main::pet is never declared. The symbolic assignment just created $main::pet. So 'use strict' threw error since it could not find any declaration for $main::pet either direct or indirect.


    Any other explanation that better explain the behavior?

    - GG1985
      > $main::pet got indirectly declared.

      you can't "declare" fully qualified pkg vars, the declaration of our and my just "links" _unqualified_ vars to a slot (be in a stash or a pad) for the compiler.

      I.e. there is no need for an "implicit" declaration. It's just the same initialization like for hash-entries.

      Cheers Rolf

      ( addicted to the Perl Programming Language)