This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/mk_PL_charclass.pl: Use mktables table for charname
[perl5.git] / regen / feature.pl
index 42632df..e1f30df 100755 (executable)
@@ -28,6 +28,7 @@ my %feature = (
     evalbytes       => 'evalbytes',
     array_base      => 'arybase',
     current_sub     => '__SUB__',
+    lexical_subs    => 'lexsubs',
     unicode_eval    => 'unieval',
     unicode_strings => 'unicode',
     fc              => 'fc',
@@ -51,6 +52,8 @@ my %feature_bundle = (
                    evalbytes current_sub fc)],
 );
 
+my @experimental = qw( lexical_subs );
+
 
 ###########################################################################
 # More data generated from the above
@@ -151,7 +154,7 @@ sub longest {
 
 print $pm "our %feature = (\n";
 my $width = length longest keys %feature;
-for(sort { length $a <=> length $b } keys %feature) {
+for(sort { length $a <=> length $b || $a cmp $b } keys %feature) {
     print $pm "    $_" . " "x($width-length)
            . " => 'feature_$feature{$_}',\n";
 }
@@ -172,6 +175,10 @@ for (sort keys %Aliases) {
        qq'\$feature_bundle{"$_"} = \$feature_bundle{"$Aliases{$_}"};\n';
 };
 
+print $pm "my \%experimental = (\n";
+print $pm "    $_ => 1,\n", for @experimental;
+print $pm ");\n";
+
 print $pm <<EOPM;
 
 our \$hint_shift   = $HintShift;
@@ -251,7 +258,7 @@ print $h <<EOL;
 EOL
 
 for (
-    sort { length $a <=> length $b } keys %feature
+    sort { length $a <=> length $b || $a cmp $b } keys %feature
 ) {
     my($first,$last) =
        map { (my $__ = uc) =~ y/.//d; $__ } @{$BundleRanges{$_}};
@@ -280,7 +287,7 @@ EOI
 
 EOH3
     }
-    else {
+    elsif ($first) {
        print $h <<EOH4;
 #define FEATURE_$NAME\_IS_ENABLED \\
     ( \\
@@ -291,6 +298,16 @@ EOH3
 
 EOH4
     }
+    else {
+       print $h <<EOH5;
+#define FEATURE_$NAME\_IS_ENABLED \\
+    ( \\
+       CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \\
+        FEATURE_IS_ENABLED("$name") \\
+    )
+
+EOH5
+    }
 }
 
 print $h <<EOH;
@@ -338,7 +355,7 @@ read_only_bottom_close_and_rename($h);
 __END__
 package feature;
 
-our $VERSION = '1.30';
+our $VERSION = '1.31';
 
 FEATURES
 
@@ -377,7 +394,7 @@ pragma.)
 =head2 Lexical effect
 
 Like other pragmas (C<use strict>, for example), features have a lexical
-effect. C<use feature qw(foo)> will only make the feature "foo" available
+effect.  C<use feature qw(foo)> will only make the feature "foo" available
 from that point to the end of the enclosing block.
 
     {
@@ -524,6 +541,20 @@ See L<perlfunc/fc> for details.
 
 This feature is available from Perl 5.16 onwards.
 
+=head2 The 'lexical_subs' feature
+
+B<WARNING>: This feature is still experimental and the implementation may
+change in future versions of Perl.  For this reason, F<feature.pm> will
+warn when you enable the feature, unless you have explicitly disabled the
+warning:
+
+    no warnings "experimental::lexical_subs";
+
+This enables declaration of subroutines via C<my sub foo>, C<state sub foo>
+and C<our sub foo> syntax.  See L<perlsub/Lexical Subroutines> for details.
+
+This feature is available from Perl 5.18 onwards.
+
 =head1 FEATURE BUNDLES
 
 It's possible to load multiple features together, using
@@ -647,6 +678,11 @@ sub __common {
        if ($import) {
            $^H{$feature{$name}} = 1;
            $^H |= $hint_uni8bit if $name eq 'unicode_strings';
+           if ($experimental{$name}) {
+               require warnings;
+               warnings::warnif("experimental::$name",
+                                "The $name feature is experimental");
+           }
        } else {
             delete $^H{$feature{$name}};
             $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';