diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-06-17 08:21:50 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-06-17 08:28:54 -0700 |
commit | 4dbb339a42f47d222b16b1c32189decd83eecfda (patch) | |
tree | 044a88077ad87b942d50307a496dcf13f0a3ddb6 /op.c | |
parent | 815dd406a7217429564c39cb160845d317b6da75 (diff) | |
download | perl-4dbb339a42f47d222b16b1c32189decd83eecfda.tar.gz |
Allow ‘sub x :lvalue’ to apply to XSUBs and stubs
This was disabled in 5.12 (with a warning) by commit 885ef6f5, because
applying the attribute to a Perl sub isn’t effective: it does not mod-
ify the op tree accordingly.
But applying an attribute to an XSUB after the fact is perfectly
fine, and is the only way to do it (either with declarative syntax or
attributes.pm). This commit restores the old behaviour of declarative
for XSUBs. (attributes.pm never stopped working.)
Commit 885ef6f5 also stopped a declaration from applying the flag to
an undefined subroutine if it happens to have been assigned from else-
where. It does not make sense to allow the :method attribute to be
applied to such a sub, but not :lvalue.
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -6217,9 +6217,13 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) )&& !attrs) { if (CvFLAGS(PL_compcv)) { /* might have had built-in attrs applied */ - if (CvLVALUE(PL_compcv) && ! CvLVALUE(cv) && ckWARN(WARN_MISC)) + const bool pureperl = !CvISXSUB(cv) && CvROOT(cv); + if (CvLVALUE(PL_compcv) && ! CvLVALUE(cv) && pureperl + && ckWARN(WARN_MISC)) Perl_warner(aTHX_ packWARN(WARN_MISC), "lvalue attribute ignored after the subroutine has been defined"); - CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS & ~CVf_LVALUE); + CvFLAGS(cv) |= + (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS + & ~(CVf_LVALUE * pureperl)); } /* just a "sub foo;" when &foo is already defined */ SAVEFREESV(PL_compcv); |