In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/80e3f4adf22ed5d8909125f2cdfe19e7ee95976a?hp=384e62c03f8c6cbf789cc9736a203bd13e5c383c>

- Log -----------------------------------------------------------------
commit 80e3f4adf22ed5d8909125f2cdfe19e7ee95976a
Author: Father Chrysostomos <[email protected]>
Date:   Tue Jun 14 18:09:22 2011 -0700

    Make B::Deparse emit CORE::state, etc.
    
    Commit 9dcb83683 enabled feature.pm-enabled keywords to work with the
    CORE:: prefix even without feature.pm.
    
    B::Deparse is hereby updated to account for this, by prefixing CORE::
    to those keywords if the feature in question is not loaded.
-----------------------------------------------------------------------

Summary of changes:
 dist/B-Deparse/Deparse.pm  |   26 ++++++++++++++++++++++----
 dist/B-Deparse/t/core.t    |    4 ++++
 dist/B-Deparse/t/deparse.t |   17 +++++++++++++++++
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm
index 7496525..b37865e 100644
--- a/dist/B-Deparse/Deparse.pm
+++ b/dist/B-Deparse/Deparse.pm
@@ -1095,7 +1095,9 @@ sub maybe_my {
     my $self = shift;
     my($op, $cx, $text) = @_;
     if ($op->private & OPpLVAL_INTRO and not $self->{'avoid_local'}{$$op}) {
-       my $my = $op->private & OPpPAD_STATE ? "state" : "my";
+       my $my = $op->private & OPpPAD_STATE
+           ? $self->keyword("state")
+           : "my";
        if (want_scalar($op)) {
            return "$my $text";
        } else {
@@ -1523,10 +1525,26 @@ sub pp_setstate { pp_nextstate(@_) }
 
 sub pp_unstack { return "" } # see also leaveloop
 
+my %feature_keywords = (
+  # keyword => 'feature',
+    state   => 'state',
+    say     => 'say',
+    given   => 'switch',
+    when    => 'switch',
+    default => 'switch',
+);
+
 sub keyword {
     my $self = shift;
     my $name = shift;
     return $name if $name =~ /^CORE::/; # just in case
+    if (exists $feature_keywords{$name}) {
+       return
+         $self->{'hinthash'}
+          && $self->{'hinthash'}{"feature_$feature_keywords{$name}"}
+           ? $name
+           : "CORE::$name";
+    }
     if (
       $name !~ /^(?:chom?p|exec|system)\z/
        && !defined eval{prototype "CORE::$name"}
@@ -1753,7 +1771,7 @@ sub givwhen {
     my $enterop = $op->first;
     my ($head, $block);
     if ($enterop->flags & OPf_SPECIAL) {
-       $head = "default";
+       $head = $self->keyword("default");
        $block = $self->deparse($enterop->first, 0);
     }
     else {
@@ -1768,8 +1786,8 @@ sub givwhen {
        "\b}\cK";
 }
 
-sub pp_leavegiven { givwhen(@_, "given"); }
-sub pp_leavewhen  { givwhen(@_, "when"); }
+sub pp_leavegiven { givwhen(@_, $_[0]->keyword("given")); }
+sub pp_leavewhen  { givwhen(@_, $_[0]->keyword("when")); }
 
 sub pp_exists {
     my $self = shift;
diff --git a/dist/B-Deparse/t/core.t b/dist/B-Deparse/t/core.t
index dcf0082..11eabc0 100644
--- a/dist/B-Deparse/t/core.t
+++ b/dist/B-Deparse/t/core.t
@@ -99,3 +99,7 @@ CORE_test values => 'CORE::values %bar', 'values %hash';
 #CORE_test not => 'CORE::not $a, $b', 'not';
 CORE_test readline => 'CORE::readline $a.$b', 'readline';
 CORE_test readpipe => 'CORE::readpipe $a+$b', 'readpipe';
+
+# Tests for prefixing feature.pm-enabled keywords with CORE:: when
+# feature.pm is not enabled are in deparse.t, as they fit that for-
+# mat better.
diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t
index 7249846..6864dae 100644
--- a/dist/B-Deparse/t/deparse.t
+++ b/dist/B-Deparse/t/deparse.t
@@ -738,3 +738,20 @@ $b::a[0] = 1;
 # aelemfast for a lexical
 my @a;
 $a[0] = 1;
+####
+# feature features without feature
+BEGIN {
+    delete $^H{'feature_say'};
+    delete $^H{'feature_state'};
+    delete $^H{'feature_switch'};
+}
+CORE::state $x;
+CORE::say $x;
+CORE::given ($x) {
+    CORE::when (3) {
+        continue;
+    }
+    CORE::default {
+        die;
+    }
+}

--
Perl5 Master Repository

Reply via email to