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

Re: Limitations of Attributes

Thread Previous | Thread Next
"Ruud H.G. van Tol" via perl5-porters
May 3, 2023 15:14
Re: Limitations of Attributes
Message ID:

On 2023-05-02 21:33, Ovid wrote:
> Attributes could really use a rethink in a number of ways and I'm 
> curious if anyone has put any thought into this?
> For example, attributes in signatures are a syntax error:
> sub foo ($bar :some_attr) { ... }
> It would also be nice if the attribute arguments could be dynamic 
> instead of just strings. Here's an example, using the signatures from 
> Type::Tiny. I have some client code which looks like this:
> use Custom::Sigs 'search_signature';
> signature_for function => search_signature();
> sub function {...}
> That particular signature is shared in several places, so it's 
> maintained in only one place. At a minimum, I'd love to do this:
> use Custom::Sigs 'SEARCH';
> sub function :signature(SEARCH) {...}
> And replace SEARCH with the results of the sub call without nasty eval 
> hacks. I'm actually working on some code to try to handle the latter 
> case, but so far I've been using the Marpa parser to develop a BNF 
> grammar to parse the Perl code in the attribute and install the 
> signature. It's very painful.

The set of instances of <function> could be implemented as
a set of minimal instances called <_function>,
and a single "wrapper" implementation of <function> itself inside some role,
that handles all the interfacing,
and then hands over to the appropriate instance of <_function>?

-- Ruud

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