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

Re: Namespaces (was Re: Revisiting trim)

Thread Previous | Thread Next
June 1, 2021 10:28
Re: Namespaces (was Re: Revisiting trim)
Message ID:
"Paul \"LeoNerd\" Evans" <> 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.

- ilmari

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About