Skip to content

Commit

Permalink
add the smartmatch feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz authored and ap committed Feb 16, 2025
1 parent cd80cda commit ed1ae14
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 48 deletions.
32 changes: 27 additions & 5 deletions feature.h

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

91 changes: 55 additions & 36 deletions lib/feature.pm

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

25 changes: 22 additions & 3 deletions regen/feature.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ BEGIN
apostrophe_as_package_separator => 'apos_as_name_sep',
any => 'any',
all => 'all',
smartmatch => 'smartmatch',
);

# NOTE: If a feature is ever enabled in a non-contiguous range of Perl
Expand All @@ -58,7 +59,7 @@ BEGIN
# 5.odd implies the next 5.even, but an explicit 5.even can override it.

# features bundles
use constant V5_9_5 => sort qw{say state switch indirect multidimensional bareword_filehandles apostrophe_as_package_separator};
use constant V5_9_5 => sort qw{say state switch indirect multidimensional bareword_filehandles apostrophe_as_package_separator smartmatch};
use constant V5_11 => sort ( +V5_9_5, qw{unicode_strings} );
use constant V5_15 => sort ( +V5_11, qw{unicode_eval evalbytes current_sub fc} );
use constant V5_23 => sort ( +V5_15, qw{postderef_qq} );
Expand All @@ -72,7 +73,8 @@ BEGIN

use constant V5_39 => sort ( +V5_37, qw{try} );
use constant V5_41 => sort
grep {; $_ ne 'apostrophe_as_package_separator' }
grep {; $_ ne 'apostrophe_as_package_separator'
&& $_ ne 'smartmatch' }
( +V5_39 );

#
Expand All @@ -81,7 +83,7 @@ BEGIN
my %feature_bundle = (
all => [ sort keys %feature ],
default => [ qw{indirect multidimensional bareword_filehandles
apostrophe_as_package_separator} ],
apostrophe_as_package_separator smartmatch} ],
# using 5.9.5 features bundle
"5.9.5" => [ +V5_9_5 ],
"5.10" => [ +V5_9_5 ],
Expand Down Expand Up @@ -701,6 +703,23 @@ =head2 The 'state' feature
This feature is available starting with Perl 5.10.
=head2 The 'smartmatch' feature
C<use feature 'smartmatch'> tells the compiler to enable the
smartmatch operator C<~~>. It is enabled by default, but can be
turned off to disallow the C<~~> operator.
This feature is disabled by default in the 5.42 feature bundle
onwards:
$x ~~ $y; # fine
use v5.42;
$x ~~ $y; # error
This has no effect on the implicit smartmatches done by C<when>.
See L<perlop/"Smartmatch Operator"> for details.
=head2 The 'switch' feature
B<WARNING>: This feature is still experimental and the implementation may
Expand Down
8 changes: 4 additions & 4 deletions t/lib/feature/api
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ BEGIN {
print "bundle: ", feature::feature_bundle(0) // "undef", "\n";
}
EXPECT
default: apostrophe_as_package_separator bareword_filehandles indirect multidimensional
default: apostrophe_as_package_separator bareword_filehandles indirect multidimensional smartmatch
unicode_strings is not enabled
bundle: default
5.12: apostrophe_as_package_separator bareword_filehandles indirect multidimensional say state switch unicode_strings
5.12: apostrophe_as_package_separator bareword_filehandles indirect multidimensional say smartmatch state switch unicode_strings
unicode_strings is enabled
bundle: 5.11
########
Expand All @@ -40,9 +40,9 @@ BEGIN {
print "bundle: ", feature::feature_bundle(0) // "undef", "\n";
}
EXPECT
no feature indirect: apostrophe_as_package_separator bareword_filehandles multidimensional
no feature indirect: apostrophe_as_package_separator bareword_filehandles multidimensional smartmatch
indirect is not enabled
bundle: undef
added unicode_strings: apostrophe_as_package_separator bareword_filehandles multidimensional unicode_strings
added unicode_strings: apostrophe_as_package_separator bareword_filehandles multidimensional smartmatch unicode_strings
unicode_strings is enabled
bundle: undef

0 comments on commit ed1ae14

Please sign in to comment.