summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-08-01 14:16:21 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-08-01 20:38:18 -0700
commitb5a648148c71e82a615a5ed312204978f88e1def (patch)
tree74c539a5878b9b141394a6de59cfe1fe006b4218 /perly.y
parenta444d2d4f3777a58d916c57753c99c6bed6a1e5d (diff)
downloadperl-b5a648148c71e82a615a5ed312204978f88e1def.tar.gz
[perl #114020, #90018, #53186] Make given alias $_
This commit makes given() alias $_ to the argument, using a slot in the lexical pad if a lexical $_ is in scope, or $'_ otherwise. This makes it work very similarly to foreach, and eliminates the problem of List::Util functions not working inside given().
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y15
1 files changed, 8 insertions, 7 deletions
diff --git a/perly.y b/perly.y
index b4bdb48253..eab7de2395 100644
--- a/perly.y
+++ b/perly.y
@@ -90,7 +90,7 @@
%type <ival> grammar remember mremember
%type <ival> startsub startanonsub startformsub
/* FIXME for MAD - are these two ival? */
-%type <ival> mydefsv mintro
+%type <ival> mintro
%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
@@ -215,10 +215,6 @@ remember: /* NULL */ /* start a full lexical scope */
{ $$ = block_start(TRUE); }
;
-mydefsv: /* NULL */ /* lexicalize $_ */
- { $$ = (I32) Perl_allocmy(aTHX_ STR_WITH_LEN("$_"), 0); }
- ;
-
mblock : '{' mremember stmtseq '}'
{ if (PL_parser->copline > (line_t)IVAL($1))
PL_parser->copline = (line_t)IVAL($1);
@@ -380,10 +376,15 @@ barestmt: PLUGSTMT
TOKEN_GETMAD($5,$$,')');
PL_parser->copline = (line_t)IVAL($1);
}
- | GIVEN '(' remember mydefsv mexpr ')' mblock
+ | GIVEN '(' remember mexpr ')' mblock
{
+ const PADOFFSET offset = pad_findmy_pvs("$_", 0);
$$ = block_end($3,
- newGIVENOP($5, op_scope($7), (PADOFFSET)$4));
+ newGIVENOP($4, op_scope($6),
+ offset == NOT_IN_PAD
+ || PAD_COMPNAME_FLAGS_isOUR(offset)
+ ? 0
+ : offset));
PL_parser->copline = (line_t)IVAL($1);
}
| WHEN '(' remember mexpr ')' mblock