Front page | perl.perl5.porters |
Postings from August 2023
Signature attributes
Thread Next
From:
Ovid
Date:
August 7, 2023 11:58
Subject:
Signature attributes
Message ID:
CA+M4CHsaKk09Kor2v5poPC=rXJTuWBnan=zoGWFL_B+bYSGp5w@mail.gmail.com
Hi all,
Currently, the following is a syntax error:
sub foo ($bar :myAttr) {...}
This has proven to be a blocker for some projects which use attributes on
declarations. For example, the Oshun project (
https://github.com/Perl-Oshun/oshun) to create dynamic runtime data checks
had to jump through a lot of hoops to make this work:
sub customer :returns(OBJ[My::Customer] | UNDEF) ( $nth :of(UINT) ) {
...
}
If we had attributes for signatures, it wouldn't be an unholy mess of PPR
and Filter::Simple.
How difficult would it be to allow subroutine arguments to accept
attributes?
Alternatively, perldoc -f my allows my TYPE VARLIST, but sub foo (INT $bar)
generates:
A signature parameter must start with '$', '@' or '%' at -e line 1
But TYPE isn't currently used much, so I'm guessing that's probably of less
value, though we've considered that syntax for the Oshun data checks.
Best,
Ovid
--
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/
Thread Next
-
Signature attributes
by Ovid