From 9dcb836830f7b4b182872b1181fb344b559c1d2e Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 11 Jun 2011 14:44:32 -0700 Subject: [PATCH] [perl #90130] Allow CORE::* without feature.pm MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commit allows feature.pm-enabled keywords to work with CORE::* even outside the scope of ‘use feature’. --- pod/perldelta.pod | 5 +++++ t/io/say.t | 7 ++++++- t/op/state.t | 8 +++++++- t/op/switch.t | 10 +++++++++- toke.c | 11 +++++++---- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 7536cae..b983ed3 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -33,6 +33,11 @@ here, but most should go in the L section. [ List each enhancement as a =head2 entry ] +=head2 C works on all keywords + +The C prefix can now be used on keywords enabled by +L, even outside the scope of C. + =head1 Security XXX Any security-related notices go here. In particular, any security diff --git a/t/io/say.t b/t/io/say.t index ead4d0b..70f83a7 100644 --- a/t/io/say.t +++ b/t/io/say.t @@ -16,7 +16,7 @@ BEGIN { use strict 'vars'; use feature "say"; -say "1..12"; +say "1..13"; my $foo = 'STDOUT'; say $foo "ok 1"; @@ -53,3 +53,8 @@ say STDOUT; local $, = "\nnot ok 13"; # how to fool Test::Harness say "ok 12"; } + +{ + no feature 'say'; + CORE::say "ok 13 - CORE::say without feature.pm"; +} diff --git a/t/op/state.t b/t/op/state.t index 611dd45..65f368b 100644 --- a/t/op/state.t +++ b/t/op/state.t @@ -8,9 +8,15 @@ BEGIN { } use strict; + +plan tests => 131; + +# Before loading feature.pm, test it with CORE:: +ok eval 'CORE::state $x = 1;', 'CORE::state outside of feature.pm scope'; + + use feature ":5.10"; -plan tests => 130; ok( ! defined state $uninit, q(state vars are undef by default) ); diff --git a/t/op/switch.t b/t/op/switch.t index 92df763..bb7569d 100644 --- a/t/op/switch.t +++ b/t/op/switch.t @@ -9,12 +9,20 @@ BEGIN { use strict; use warnings; -plan tests => 166; +plan tests => 168; # The behaviour of the feature pragma should be tested by lib/feature.t # using the tests in t/lib/feature/*. This file tests the behaviour of # the switch ops themselves. + +# Before loading feature, test the switch ops with CORE:: +CORE::given(3) { + CORE::when(3) { pass "CORE::given and CORE::when"; CORE::continue } + CORE::default { pass "CORE::continue and CORE::default" } +} + + use feature 'switch'; eval { continue }; diff --git a/toke.c b/toke.c index 4860bd5..1e4beee 100644 --- a/toke.c +++ b/toke.c @@ -7055,11 +7055,12 @@ Perl_yylex(pTHX) s += 2; d = s; s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); - if (!(tmp = keyword(PL_tokenbuf, len, 0))) + if (!(tmp = keyword(PL_tokenbuf, len, 1))) Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); if (tmp < 0) tmp = -tmp; - else if (tmp == KEY_require || tmp == KEY_do) + if (tmp == KEY_require || tmp == KEY_do || + tmp == KEY_continue) /* that's a way to remember we saw "CORE::" */ orig_keyword = tmp; goto reserved_word; @@ -7099,10 +7100,12 @@ Perl_yylex(pTHX) UNI(OP_CHOP); case KEY_continue: - /* When 'use switch' is in effect, continue has a dual + /* When 'use switch' is in effect or when + prefixed with CORE::, continue has a dual life as a control operator. */ { - if (!FEATURE_IS_ENABLED("switch")) + if ( !FEATURE_IS_ENABLED("switch") + && orig_keyword != KEY_continue ) PREBLOCK(CONTINUE); else { /* We have to disambiguate the two senses of -- 2.7.4