summaryrefslogtreecommitdiff
path: root/pp_ctl.c
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 /pp_ctl.c
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 'pp_ctl.c')
-rw-r--r--pp_ctl.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index ca953ad05e..cb549fa841 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4273,8 +4273,15 @@ PP(pp_entergiven)
ENTER_with_name("given");
SAVETMPS;
- SAVECLEARSV(PAD_SVl(PL_op->op_targ));
- sv_setsv_mg(PAD_SV(PL_op->op_targ), POPs);
+ if (PL_op->op_targ) {
+ SAVEPADSVANDMORTALIZE(PL_op->op_targ);
+ SvREFCNT_dec(PAD_SVl(PL_op->op_targ));
+ PAD_SVl(PL_op->op_targ) = SvREFCNT_inc_NN(POPs);
+ }
+ else {
+ SAVE_DEFSV;
+ DEFSV_set(POPs);
+ }
PUSHBLOCK(cx, CXt_GIVEN, SP);
PUSHGIVEN(cx);