summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-06-14 18:09:22 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-06-14 21:28:42 -0700
commit80e3f4adf22ed5d8909125f2cdfe19e7ee95976a (patch)
tree53fbcdeb76050e77bb4a5678072114dd2b216131 /dist
parent384e62c03f8c6cbf789cc9736a203bd13e5c383c (diff)
downloadperl-80e3f4adf22ed5d8909125f2cdfe19e7ee95976a.tar.gz
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.
Diffstat (limited to 'dist')
-rw-r--r--dist/B-Deparse/Deparse.pm26
-rw-r--r--dist/B-Deparse/t/core.t4
-rw-r--r--dist/B-Deparse/t/deparse.t17
3 files changed, 43 insertions, 4 deletions
diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm
index 7496525a78..b37865e60e 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 dcf0082915..11eabc0f8b 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 72498465a2..6864dae529 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;
+ }
+}