diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-01 14:16:21 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-08-01 20:38:18 -0700 |
commit | b5a648148c71e82a615a5ed312204978f88e1def (patch) | |
tree | 74c539a5878b9b141394a6de59cfe1fe006b4218 /pp_ctl.c | |
parent | a444d2d4f3777a58d916c57753c99c6bed6a1e5d (diff) | |
download | perl-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.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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); |