Skip to content

Commit f18ab64

Browse files
committed
Add some notes specifically pointing out the added Perl-level syntax of sub signature param attributes
1 parent ca25572 commit f18ab64

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ppcs/ppcTODO-attributes-v2.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ When the parser is parsing perl code and finds an attribute declaration attached
7575

7676
When attached to a package variable or package-named function, the target can be the entity itself (or maybe indirectly, its GV). When attached to a lexical, it is important to pass in the abstract concept of the target in general, rather than the current item in its scope pad. There is currently no suitable kind of SV to represent this - this remains another interesting open issue.
7777

78-
Additionally, new callsites can be added to the parser to invoke attribute callbacks in new situations that previously were not permitted; such as package declarations or subroutine parameters.
78+
Additionally, new callsites can be added to the parser to invoke attribute callbacks in new situations that previously were not permitted. It would be a simple extension of the syntax of attributes on lexical variables to additionally have them apply to subroutine signature parameters.
79+
80+
```perl
81+
sub func ( $x, $y :Attr, $z :Attr(Value) ) { ... }
82+
```
83+
84+
Beyond this, this particular specification does not suggest any other places to accept attribute syntax, but this is noted in the "Future Scope" section below.
7985

8086
Note that this specification does not provide a mechanism by which attributes can declare what kinds of targets they are applicable to. Any particular named attribute will be attempted for _any_ kind of target that the parser finds. This is intentional, as it leads to a simpler model both for the interpreter and for human readers of the code, as it means any particular attribute name has at most one definition; its definition does not depend on the type of target to which it is applied. It is the job of the attribute callback itself to enquire what kind of target it has been invoked on, and reject it if necessary - likely with a `croak()` call of some appropriate message.
8187

@@ -95,6 +101,15 @@ As there is no interesting result returned from the attribute callback function,
95101
96102
The new mechanism proposed here is entirely lexically scoped. Any attributes introduced into a scope will not be visible from outside. As such, it is an entirely opt-in effect that would not cause issues for existing code that is not expecting it.
97103
104+
The only Perl-level change of syntax suggested here is to permit applying attributes to subroutine parameters. The suggested syntax for this is currently a compile-time syntax error in Perl, so this should cause no problem.
105+
106+
```
107+
$ perl -E 'use feature "signatures"; sub f ( $x :Attr ) { }'
108+
Illegal operator following parameter in a subroutine signature at -e line 1, near "( $x :Attr "
109+
syntax error at -e line 1, near "( $x :Attr "
110+
Execution of -e aborted due to compilation errors.
111+
```
112+
98113
## Security Implications
99114
100115
## Examples

0 commit comments

Comments
 (0)