in reply to Re: Pure perl lexical sub import
in thread Pure perl lexical sub import

So you mean basically have a scope where they're imported be a different package than what eventually holds the object methods, by copying out the functions into that other package?

I suppose it works, but I'm having trouble imagining how I would structure things so that it is less ugly than just calling the external function by its full name in the intended package.

Replies are listed 'Best First'.
Re^3: Pure perl lexical sub import
by Arunbear (Prior) on Dec 23, 2024 at 12:39 UTC
    There'd be one package which is your actual clean namespace meant for end users, and another package containing the implementation details.

    It only looks ugly because I was tired and didn't use Exporter. So with Exporter it would be like this

    :::::::::::::: Foo/Internal.pm :::::::::::::: use v5.36; package Foo::Internal { use Exporter 'import'; our @EXPORT = qw[check_it]; use Scalar::Util 'looks_like_number'; sub check_it ($self, $num) { say 'Hoorah!' if looks_like_number($num); } } 1; :::::::::::::: Foo.pm :::::::::::::: use v5.36; package Foo { use Foo::Internal; sub new ($class) { bless {} => $class; } } 1; :::::::::::::: clean.pl :::::::::::::: use v5.36; use Foo; my $foo = Foo->new; $foo->check_it(42); $foo->looks_like_number(42);