The documentation suggests the following experimental way to set signatures
for subroutines.
```
To declare subroutines:
sub NAME; # A "forward" declaration.
sub NAME(PROTO); # ditto, but with prototypes
sub NAME : ATTRS; # with attributes
sub NAME(PROTO) : ATTRS; # with attributes and prototypes
sub NAME BLOCK # A declaration and a definition.
sub NAME(PROTO) BLOCK # ditto, but with prototypes
sub NAME : ATTRS BLOCK # with attributes
sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes
use feature 'signatures';
sub NAME(SIG) BLOCK # with signature
# ^ At this point, we see the intersection of syntax
sub NAME :ATTRS (SIG) BLOCK # with signature, attributesS
sub NAME :prototype(PROTO) (SIG) BLOCK # with signature, prototype
```
The parser needs to know about the lexical scoping context in order to
determine what is inside the parentheses, SIG or PROTO.
This complicates, in particular, the work of syntax highlighting in the
editor.
I propose to introduce a new keyword to avoid confusion. For example fn.
```
To declare subroutines:
sub NAME; # A "forward" declaration.
sub NAME(PROTO); # ditto, but with prototypes
sub NAME : ATTRS; # with attributes
sub NAME(PROTO) : ATTRS; # with attributes and prototypes
sub NAME BLOCK # A declaration and a definition.
sub NAME(PROTO) BLOCK # ditto, but with prototypes
sub NAME : ATTRS BLOCK # with attributes
sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes
use feature 'signatures';
fn NAME(SIG) BLOCK # with signature
fn NAME :ATTRS (SIG) BLOCK # with signature, attributes
fn NAME :prototype(PROTO) (SIG) BLOCK # with signature, prototype
```
This is the approach used in Method::Signatures.
As a bonus, we have the opportunity in the future to get rid of the
sub(routine) designation, which smells of antiquity.
Which may affect the image of perl as a legacy development tool.
In the documentation, by the way, both designations are used.
```
$ perldoc perlsub | grep -io 'function\|subroutine' | sort | uniq -ic
70 function
148 subroutine
```
for subroutines.
```
To declare subroutines:
sub NAME; # A "forward" declaration.
sub NAME(PROTO); # ditto, but with prototypes
sub NAME : ATTRS; # with attributes
sub NAME(PROTO) : ATTRS; # with attributes and prototypes
sub NAME BLOCK # A declaration and a definition.
sub NAME(PROTO) BLOCK # ditto, but with prototypes
sub NAME : ATTRS BLOCK # with attributes
sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes
use feature 'signatures';
sub NAME(SIG) BLOCK # with signature
# ^ At this point, we see the intersection of syntax
sub NAME :ATTRS (SIG) BLOCK # with signature, attributesS
sub NAME :prototype(PROTO) (SIG) BLOCK # with signature, prototype
```
The parser needs to know about the lexical scoping context in order to
determine what is inside the parentheses, SIG or PROTO.
This complicates, in particular, the work of syntax highlighting in the
editor.
I propose to introduce a new keyword to avoid confusion. For example fn.
```
To declare subroutines:
sub NAME; # A "forward" declaration.
sub NAME(PROTO); # ditto, but with prototypes
sub NAME : ATTRS; # with attributes
sub NAME(PROTO) : ATTRS; # with attributes and prototypes
sub NAME BLOCK # A declaration and a definition.
sub NAME(PROTO) BLOCK # ditto, but with prototypes
sub NAME : ATTRS BLOCK # with attributes
sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes
use feature 'signatures';
fn NAME(SIG) BLOCK # with signature
fn NAME :ATTRS (SIG) BLOCK # with signature, attributes
fn NAME :prototype(PROTO) (SIG) BLOCK # with signature, prototype
```
This is the approach used in Method::Signatures.
As a bonus, we have the opportunity in the future to get rid of the
sub(routine) designation, which smells of antiquity.
Which may affect the image of perl as a legacy development tool.
In the documentation, by the way, both designations are used.
```
$ perldoc perlsub | grep -io 'function\|subroutine' | sort | uniq -ic
70 function
148 subroutine
```