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

Re: Namespaces (was Re: Revisiting trim)

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
May 28, 2021 20:48
Subject:
Re: Namespaces (was Re: Revisiting trim)
Message ID:
20210528214829.0d5463b1@shy.leonerd.org.uk
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.

Already I have begun experimenting with keyword-implemented list
utility functions under List::Keywords - and those have the property of
only being lexically visible and not visible as object/class methods:

$ perl -e \
  'package My::Class { use List::Keywords 'all' } My::Class->all(1,2,3)'
Can't locate object method "all" via package "My::Class" at -e line 1.

It would be great if the same could be said of

$ perl -e \
  'package My::Class { use keyword 'string::trimmed' } ...

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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