diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-08-27 23:29:13 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-08-27 23:37:48 -0700 |
commit | 7bc95ae1a56bd0ccfe9db1092344cd2d1566beca (patch) | |
tree | 98d78f818036eec595f3ceb97a6d10cad0d11eb9 /op.c | |
parent | d22667bf3cdadad95b9d176de3bf87d0b0e1286e (diff) | |
download | perl-7bc95ae1a56bd0ccfe9db1092344cd2d1566beca.tar.gz |
&CORE::substr()
This commit makes &CORE::substr callable through references and via
&ersand syntax.
It’s a bit awkward, as we need a substr op that is flagged as hav-
ing 4 arguments *and* possibly returning an lvalue. The code in
op_lvalue_flags wasn’t really set up for that, so I needed to flag
the op with OPpMAYBE_LVSUB in coresub_op before it gets passed to
op_lvalue_flags. It turned out that only that was necessary, as
op_lvalue_flags does an op_private == 4 check (rather than (op_private
& 7) == 4 or some such) when checking for the 4-arg case and croak-
ing. When the op arrives in op_lvalue_flags, it’s already flagged
OPpMAYBE_LVSUB|4 which != 4.
pp_substr is also modified to check for nulls and, if necessary,
adjust its count of how many arguments were actually passed.)
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -10397,7 +10397,11 @@ Perl_coresub_op(pTHX_ SV * const coreargssv, const int code, argop->op_private |= OPpCOREARGS_DEREF2; if (scalar_mod_type(NULL, opnum)) argop->op_private |= OPpCOREARGS_SCALARMOD; - goto onearg; + if (opnum == OP_SUBSTR) { + o->op_private |= OPpMAYBE_LVSUB; + return o; + } + else goto onearg; } } } |