From 4b473a5a056427bc93ffb46dbb873c9e6ec5287f Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 2 Jul 2012 21:26:13 -0700 Subject: [PATCH] Make do sub() respect our declarations --- t/cmd/lexsub.t | 10 +++++++++- toke.c | 11 ++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/t/cmd/lexsub.t b/t/cmd/lexsub.t index 0732678..02bb71c 100644 --- a/t/cmd/lexsub.t +++ b/t/cmd/lexsub.t @@ -2,25 +2,30 @@ BEGIN { chdir 't'; + @INC = '../lib'; require './test.pl'; *bar::is = *is; } -plan 13; +no warnings 'deprecated'; +plan 19; { our sub foo { 42 } is foo, 42, 'calling our sub from same package'; is &foo, 42, 'calling our sub from same package (amper)'; + is do foo(), 42, 'calling our sub from same package (do)'; package bar; sub bar::foo { 43 } { local $::TODO = ' '; is foo, 42, 'calling our sub from another package'; } is &foo, 42, 'calling our sub from another package (amper)'; + is do foo(), 42, 'calling our sub from another package (do)'; } package bar; is foo, 43, 'our sub falling out of scope'; is &foo, 43, 'our sub falling out of scope (called via amper)'; +is do foo(), 43, 'our sub falling out of scope (called via amper)'; package main; { sub bar::a { 43 } @@ -29,6 +34,7 @@ package main; package bar; is a, 43, 'our sub invisible inside itself'; is &a, 43, 'our sub invisible inside itself (called via amper)'; + is do a(), 43, 'our sub invisible inside itself (called via do)'; } 42 } @@ -42,6 +48,7 @@ package main; is b, 42, 'our sub visible inside itself after decl'; } is &b, 42, 'our sub visible inside itself after decl (amper)'; + is do b(), 42, 'our sub visible inside itself after decl (do)'; } 42 } @@ -56,6 +63,7 @@ sub bar::c { 43 } is c, 42, 'our sub foo; makes lex alias for existing sub'; } is &c, 42, 'our sub foo; makes lex alias for existing sub (amper)'; + is do c(), 42, 'our sub foo; makes lex alias for existing sub (do)'; } { our sub d; diff --git a/toke.c b/toke.c index 1a82259..6912863 100644 --- a/toke.c +++ b/toke.c @@ -7423,10 +7423,15 @@ Perl_yylex(pTHX) if (*s == '{') PRETERMBLOCK(DO); if (*s != '\'') { - d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, 1, &len); - if (len) { + *PL_tokenbuf = '&'; + d = scan_word(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, + 1, &len); + if (len && !keyword(PL_tokenbuf + 1, len, 0)) { d = SKIPSPACE1(d); - if (*d == '(') s = force_word(s,WORD,TRUE,TRUE,FALSE); + if (*d == '(') { + PL_pending_ident = '&'; + s = d; + } } } if (orig_keyword == KEY_do) { -- 2.7.4