in reply to Flexibility in Module for Import or Execute

You could check if $0 matches __FILE__, but $0 is not a read-only variable, so it's possible that some module you've used has changed it.

Or you could use the core Perl function designed for this kind of thing... caller.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name