in reply to How to programmatically determine package where a sub was called

kcott mentions caller which does indeed do what you want. However, it's worth mentioning that Moo doesn't use that technique.

Instead, when you import the has keyword into your class, Moo builds a custom has function just for you, which always adds attributes to your class, no matter where it's called from. Demonstration:

use v5.12; { package Foo; use Moo; { package Goo; # The caller here is "Goo". Foo::has( xxx => (is => 'ro') ); } } # But the attribute was created in "Foo"! say Foo->can('xxx');

This is not as difficult as it sounds.

Moose does more or less the same thing. Mouse doesn't; Mouse looks at caller.

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