This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge the code common to feature::import and feature::unimport.
authorNicholas Clark <nick@ccl4.org>
Mon, 27 Feb 2012 17:24:57 +0000 (18:24 +0100)
committerNicholas Clark <nick@ccl4.org>
Mon, 19 Mar 2012 09:21:54 +0000 (10:21 +0100)
lib/feature.pm
regen/feature.pl

index bc32328..adaff96 100644 (file)
@@ -322,29 +322,7 @@ sub import {
         croak("No features specified");
     }
 
-    if (my $features = current_bundle) {
-       # Features are enabled implicitly via bundle hints.
-       normalise_hints $features;
-    }
-    while (@_) {
-        my $name = shift;
-        if (substr($name, 0, 1) eq ":") {
-            my $v = substr($name, 1);
-            if (!exists $feature_bundle{$v}) {
-                $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
-                if (!exists $feature_bundle{$v}) {
-                    unknown_feature_bundle(substr($name, 1));
-                }
-            }
-            unshift @_, @{$feature_bundle{$v}};
-            next;
-        }
-        if (!exists $feature{$name}) {
-            unknown_feature($name);
-        }
-        $^H{$feature{$name}} = 1;
-        $^H |= $hint_uni8bit if $name eq 'unicode_strings';
-    }
+    __common(1, @_);
 }
 
 sub unimport {
@@ -356,6 +334,12 @@ sub unimport {
        return;
     }
 
+    __common(0, @_);
+}
+
+
+sub __common {
+    my $import = shift;
     if (my $features = current_bundle) {
        # Features are enabled implicitly via bundle hints.
        normalise_hints $features;
@@ -376,7 +360,10 @@ sub unimport {
         if (!exists $feature{$name}) {
             unknown_feature($name);
         }
-        else {
+       if ($import) {
+           $^H{$feature{$name}} = 1;
+           $^H |= $hint_uni8bit if $name eq 'unicode_strings';
+       } else {
             delete $^H{$feature{$name}};
             $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
         }
index 6d276ce..79aa471 100755 (executable)
@@ -606,29 +606,7 @@ sub import {
         croak("No features specified");
     }
 
-    if (my $features = current_bundle) {
-       # Features are enabled implicitly via bundle hints.
-       normalise_hints $features;
-    }
-    while (@_) {
-        my $name = shift;
-        if (substr($name, 0, 1) eq ":") {
-            my $v = substr($name, 1);
-            if (!exists $feature_bundle{$v}) {
-                $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
-                if (!exists $feature_bundle{$v}) {
-                    unknown_feature_bundle(substr($name, 1));
-                }
-            }
-            unshift @_, @{$feature_bundle{$v}};
-            next;
-        }
-        if (!exists $feature{$name}) {
-            unknown_feature($name);
-        }
-        $^H{$feature{$name}} = 1;
-        $^H |= $hint_uni8bit if $name eq 'unicode_strings';
-    }
+    __common(1, @_);
 }
 
 sub unimport {
@@ -640,6 +618,12 @@ sub unimport {
        return;
     }
 
+    __common(0, @_);
+}
+
+
+sub __common {
+    my $import = shift;
     if (my $features = current_bundle) {
        # Features are enabled implicitly via bundle hints.
        normalise_hints $features;
@@ -660,7 +644,10 @@ sub unimport {
         if (!exists $feature{$name}) {
             unknown_feature($name);
         }
-        else {
+       if ($import) {
+           $^H{$feature{$name}} = 1;
+           $^H |= $hint_uni8bit if $name eq 'unicode_strings';
+       } else {
             delete $^H{$feature{$name}};
             $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
         }