From e7d0b8012b8b3d92c39255cf40044c8233629cec Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 15 Sep 2012 22:03:35 -0700 Subject: [PATCH] Disable lexsubs outside of feature.pm --- pod/perldiag.pod | 8 ++++++++ t/cmd/lexsub.t | 18 ++++++++++++++++-- t/lib/croak/toke | 9 ++++++--- t/lib/warnings/toke | 5 +++-- toke.c | 7 +++++++ 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index fd09b65..e579b11 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1860,6 +1860,14 @@ as a goto, or a loop control statement. (W exiting) You are exiting a substitution by unconventional means, such as a return, a goto, or a loop control statement. +=item Experimental "%s" subs not enabled + +(F) To use lexical subs, you must first enable them: + + no warnings 'experimental:lexical_subs'; + use feature 'lexical_subs'; + my sub foo { ... } + =item Explicit blessing to '' (assuming package main) (W misc) You are blessing a reference to a zero length string. This has diff --git a/t/cmd/lexsub.t b/t/cmd/lexsub.t index d7601b3..4dc223f 100644 --- a/t/cmd/lexsub.t +++ b/t/cmd/lexsub.t @@ -8,10 +8,24 @@ BEGIN { *bar::like = *like; } no warnings 'deprecated'; -plan 124; +plan 127; + +# -------------------- Errors with feature disabled -------------------- # + +eval "#line 8 foo\nmy sub foo"; +is $@, qq 'Experimental "my" subs not enabled at foo line 8.\n', + 'my sub unexperimental error'; +eval "#line 8 foo\nCORE::state sub foo"; +is $@, qq 'Experimental "state" subs not enabled at foo line 8.\n', + 'state sub unexperimental error'; +eval "#line 8 foo\nour sub foo"; +is $@, qq 'Experimental "our" subs not enabled at foo line 8.\n', + 'our sub unexperimental error'; # -------------------- our -------------------- # +no warnings "experimental:lexical_subs"; +use feature 'lexical_subs'; { our sub foo { 42 } is foo, 42, 'calling our sub from same package'; @@ -84,7 +98,7 @@ sub bar::c { 43 } # -------------------- state -------------------- # -use 5.01; # state +use feature 'state'; # state { state sub foo { 44 } isnt \&::foo, \&foo, 'state sub is not stored in the package'; diff --git a/t/lib/croak/toke b/t/lib/croak/toke index f979ea0..01cb751 100644 --- a/t/lib/croak/toke +++ b/t/lib/croak/toke @@ -10,19 +10,22 @@ EXPECT Can't find string terminator "foo" anywhere before EOF at (eval 1) line 1. ######## # NAME Missing name in "my sub" -my sub; +use feature 'lexical_subs'; my sub; EXPECT +The lexical_subs feature is experimental at - line 1. Missing name in "my sub" at - line 1. ######## # NAME Missing name in "our sub" -our sub; +use feature 'lexical_subs'; our sub; EXPECT +The lexical_subs feature is experimental at - line 1. Missing name in "our sub" at - line 1. ######## # NAME Missing name in "state sub" -use 5.01; +use 5.01; use feature 'lexical_subs'; state sub; EXPECT +The lexical_subs feature is experimental at - line 1. Missing name in "state sub" at - line 2. ######## # NAME Unterminated delimiter for here document diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index a0abb1b..34003c2 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -1133,7 +1133,7 @@ Use of :locked is deprecated at - line 4. Use of :locked is deprecated at - line 6. ######## # toke.c -use warnings "syntax"; +use warnings "syntax"; use feature 'lexical_subs'; sub proto_after_array(@$); sub proto_after_arref(\@$); sub proto_after_arref2(\[@$]); @@ -1147,7 +1147,7 @@ sub underscore_fail($_$); sub underscore_after_at(@_); our sub hour (@$); my sub migh (@$); -use 5.01; +use feature 'state'; state sub estate (@$); package other; sub hour (@$); @@ -1158,6 +1158,7 @@ sub proto_after_array(@$); sub proto_after_hash(%$); sub underscore_fail($_$); EXPECT +The lexical_subs feature is experimental at - line 2. Prototype after '@' for main::proto_after_array : @$ at - line 3. Prototype after '%' for main::proto_after_hash : %$ at - line 7. Illegal character after '_' in prototype for main::underscore_fail : $_$ at - line 12. diff --git a/toke.c b/toke.c index dee5768..e5fc735 100644 --- a/toke.c +++ b/toke.c @@ -7834,7 +7834,14 @@ Perl_yylex(pTHX) #endif s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) + { + if (!FEATURE_LEXSUBS_IS_ENABLED) + Perl_croak(aTHX_ + "Experimental \"%s\" subs not enabled", + tmp == KEY_my ? "my" : + tmp == KEY_state ? "state" : "our"); goto really_sub; + } PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); if (!PL_in_my_stash) { char tmpbuf[1024]; -- 2.7.4