feature.pl: Gen %feature_bundle from %UniqueBundles
authorFather Chrysostomos <sprout@cpan.org>
Thu, 22 Dec 2011 18:05:16 +0000 (10:05 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 24 Dec 2011 17:25:13 +0000 (09:25 -0800)
%UniqueBundles was added for generating constants in feature.h, but
we can use it for feature.pm’s %feature_bundle as well, simplify-
ing the code.

This eliminates this piece of code in feature.pm, spelling it
out longhand:

# Each of these is the same as the previous bundle
for (12,13,14,16) {
    $feature_bundle{"5.$_"} = $feature_bundle{"5.".($_-1)}
}

While that code might be neat, it would make the generation code
unduly complex.  (It was designed for hand-editing anyway.)

lib/feature.pm
regen/feature.pl

index a3cfdbe..34727f0 100644 (file)
@@ -25,15 +25,15 @@ our %feature_bundle = (
     "5.10"    => [qw(array_base say state switch)],
     "5.11"    => [qw(array_base say state switch unicode_strings)],
     "5.15"    => [qw(current_sub evalbytes say state switch unicode_eval unicode_strings)],
-    "5.9.5"   => [qw(array_base say state switch)],
     "default" => [qw(array_base)],
 );
 
+$feature_bundle{"5.12"} = $feature_bundle{"5.11"};
+$feature_bundle{"5.13"} = $feature_bundle{"5.11"};
+$feature_bundle{"5.14"} = $feature_bundle{"5.11"};
+$feature_bundle{"5.16"} = $feature_bundle{"5.15"};
+$feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
 
-# Each of these is the same as the previous bundle
-for (12,13,14,16) {
-    $feature_bundle{"5.$_"} = $feature_bundle{"5.".($_-1)}
-}
 # This gets set (for now) in $^H as well as in %^H,
 # for runtime speed of the uc/lc/ucfirst/lcfirst functions.
 # See HINT_UNI_8_BIT in perl.h.
index d4e2336..018ed0f 100644 (file)
@@ -98,31 +98,19 @@ for(sort { length $a <=> length $b } keys %default_feature) {
 print $pm ");\n\n";
 
 print $pm "our %feature_bundle = (\n";
-my $prevkey;
-my $prev;
-my @same;
-$width = length longest keys %feature_bundle;
-for( sort keys %feature_bundle ) {
-    my $value = join(' ', sort @{$feature_bundle{$_}});
-    if (/^5\.\d\d\z/ && $prevkey
-        && substr($_,-2) - substr($prevkey,-2) == 1 && $value eq $prev) {
-       push @same, $_;
-       $prevkey = $_;
-       next;
-    }
-    if(/^5\.\d\d\z/) {
-       $prev = $value;
-       $prevkey = $_;
-    }
-    print $pm qq'    "$_"' . " "x($width-length) . qq' => [qw($value)],\n';
+$width = length longest values %UniqueBundles;
+for( sort { $UniqueBundles{$a} cmp $UniqueBundles{$b} }
+          keys %UniqueBundles ) {
+    my $bund = $UniqueBundles{$_};
+    print $pm qq'    "$bund"' . " "x($width-length $bund)
+           . qq' => [qw($_)],\n';
 }
 print $pm ");\n\n";
 
-print $pm "
-# Each of these is the same as the previous bundle
-for (", join(',',map /\.(.*)/, @same), ') {
-    $feature_bundle{"5.$_"} = $feature_bundle{"5.".($_-1)}
-}';
+for (sort keys %Aliases) {
+    print $pm
+       qq'\$feature_bundle{"$_"} = \$feature_bundle{"$Aliases{$_}"};\n';
+};
 
 
 while (<DATA>) {
@@ -144,7 +132,7 @@ perlh: {
         or die "Non-contiguous bits in $bits (binary for $hex):\n\n$_\n ";
        $HintShift = length $1;
        my $bits_needed =
-           length sprintf "%b", scalar keys(%feature_bundle) - @same;
+           length sprintf "%b", scalar keys %UniqueBundles;
        $bits =~ /1{$bits_needed}/
            or die "Not enough bits (need $bits_needed)"
                 . " in $bits (binary for $hex):\n\n$_\n";