develooper Front page | perl.perl5.porters | Postings from June 2021

Re: Namespaces (was Re: Revisiting trim)

Thread Previous | Thread Next
From:
ilmari
Date:
June 1, 2021 10:28
Subject:
Re: Namespaces (was Re: Revisiting trim)
Message ID:
87v96xlw06.fsf@wibble.ilmari.org
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> writes:

> Unclear from this discussion whether it was explicitly pointed out, but
> one thing I'd like to see from the "keyword" functions is that they
> *not* appear in the package's symbol table.
>
> It's annoying enough that when you do this
>
>   package My::Class;
>   use Scalar::Util 'weaken';
>   ...
>
> Then `weaken` is visible as a method:
>
>   My::Class->weaken( ... )
>   $myobj->weaken( ... )
>
> It would be great if code could enable keyword-shaped operators like
> "trim(med)?" and so on without adding massively to their exposed "API"
> shape.

It is possible to export subs (and other symbols) to the calling lexical
scope, not just to the package.  There are several modules that do this
on CPAN, e.g. https://metacpan.org/pod/Lexical::Var.

- ilmari

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About