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

Limitations of Attributes

Thread Next
From:
Ovid
Date:
May 2, 2023 19:33
Subject:
Limitations of Attributes
Message ID:
CA+M4CHv+GDDF0SWJd-YtJ0wA-Fn-5NddWqp+ujVBGk0wd-XEzg@mail.gmail.com
Hi all,

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.

Best,
Ovid

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