Skip to content

Commit

Permalink
Add 'signatures' to :5.36 feature bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Feb 20, 2022
1 parent 088588b commit 3d1a4f0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
5 changes: 3 additions & 2 deletions feature.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions lib/feature.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions pod/perldelta.pod
Expand Up @@ -31,17 +31,16 @@ here, but most should go in the L</Performance Enhancements> section.

Introduced in Perl version 5.20.0, and modified several times since, the
subroutine signatures feature (C<use feature 'signatures'>) is now no longer
considered experimental.
considered experimental. It is now considered a stable language feature and
is included in the C<:5.36> feature bundle, enabled automatically by
C<use v5.36>, and no longer prints a warning.

use warnings;
use feature 'signatures';
use v5.36;

sub add ($x, $y) {
return $x + $y;
}

No longer prints a warning.

Despite this, certain elements of signatured subroutines remain
experimental; see below.

Expand All @@ -58,7 +57,7 @@ argument array or an element thereof (C<@_> or C<$_[INDEX]>), either
explicitly or implicitly (such as C<shift> or C<pop> with no argument) will
provoke a warning at compile-time:

use feature 'signatures';
use v5.36;

sub f ($x, $y = 123) {
say "The first argument is $_[0]";
Expand Down
5 changes: 4 additions & 1 deletion pod/perlexperiment.pod
Expand Up @@ -159,7 +159,10 @@ subroutine signatures.

Using the default arguments array (C<@_>) within a subroutine that uses
signatures will emit a warning in the category
C<experimental::args_array_with_signatures>.
C<experimental::args_array_with_signatures>. This includes C<@_> directly,
elements of it such as C<$_[$index]>, or situations where the default
arguments array is accessed implicitly such as C<shift> or C<pop> without
arguments.

=back

Expand Down
8 changes: 5 additions & 3 deletions pod/perlsub.pod
Expand Up @@ -321,10 +321,12 @@ explicitly. See L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">
X<formal parameter> X<parameter, formal>

Perl has a facility to allow a subroutine's formal parameters to be
introduced by special syntax, separate from the procedural code of the
declared by special syntax, separate from the procedural code of the
subroutine body. The formal parameter list is known as a I<signature>.
The facility must be enabled first by a pragmatic declaration,
C<use feature 'signatures'>.

This facility must be enabled before it can be used. It is enabled
automatically by a C<use v5.36> (or higher) declaration, or more
directly by C<use feature 'signatures'>, in the current scope.

The signature is part of a subroutine's body. Normally the body of a
subroutine is simply a braced block of code, but when using a signature,
Expand Down
13 changes: 8 additions & 5 deletions regen/feature.pl
Expand Up @@ -60,7 +60,7 @@ BEGIN
use constant V5_35 => sort grep {; $_ ne 'switch'
&& $_ ne 'bareword_filehandles'
&& $_ ne 'indirect'
&& $_ ne 'multidimensional' } +V5_27, qw{isa};
&& $_ ne 'multidimensional' } +V5_27, qw{isa signatures};

my %feature_bundle = (
all => [ sort keys %feature ],
Expand Down Expand Up @@ -702,13 +702,15 @@ =head2 The 'postderef' and 'postderef_qq' features
=head2 The 'signatures' feature
This enables unpacking of subroutine arguments into lexical variables
by syntax such as
This enables syntax for declaring subroutine arguments as lexical variables.
For example, for this suroutine:
sub foo ($left, $right) {
return $left + $right;
return $left + $right;
}
Calling C<foo(3, 7)> will assign C<3> into C<$left> and C<7> into C<$right>.
See L<perlsub/Signatures> for details.
This feature is available from Perl 5.20 onwards. From Perl 5.20 to 5.34,
Expand All @@ -719,7 +721,8 @@ =head2 The 'signatures' feature
As of Perl 5.36, use of this feature no longer triggers a warning, though the
C<experimental::signatures> warning category still exists (for compatibility
with code that disables it).
with code that disables it). This feature is now considered stable, and is
enabled automatically by C<use v5.36> (or higher).
=head2 The 'refaliasing' feature
Expand Down

0 comments on commit 3d1a4f0

Please sign in to comment.