From bb3abb059a118f508179df292a0a6e562767107f Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 21 Jun 2011 23:02:25 -0700 Subject: =?UTF-8?q?attributes.pm:=20warn=20&=20don=E2=80=99t=20apply=20:lv?= =?UTF-8?q?alue=20to=20defined=20subs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is something that ‘sub foo :lvalue;’ declarations do. This brings attributes.pm in line with them. See commits fff96ff and 885ef6f, ticket #68758, and <364E1F98-FDCC-49A7-BADB-BD844626B8AE@cpan.org>. --- ext/attributes/attributes.pm | 9 +++++++++ ext/attributes/attributes.xs | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'ext') diff --git a/ext/attributes/attributes.pm b/ext/attributes/attributes.pm index f79db0fd8c..a7c6716f57 100644 --- a/ext/attributes/attributes.pm +++ b/ext/attributes/attributes.pm @@ -34,6 +34,15 @@ sub _modify_attrs_and_deprecate { require warnings; warnings::warnif('deprecated', "Attribute \"$1\" is deprecated"); 0; + } : $svtype eq 'CODE' && /^-?lvalue\z/ ? do { + require warnings; + warnings::warnif( + 'misc', + "lvalue attribute " + . (/^-/ ? "cannot be removed" : "ignored") + . " after the subroutine has been defined" + ); + 0; } : 1 } _modify_attrs(@_); } diff --git a/ext/attributes/attributes.xs b/ext/attributes/attributes.xs index 20dc33d187..24f5f6185e 100644 --- a/ext/attributes/attributes.xs +++ b/ext/attributes/attributes.xs @@ -48,6 +48,10 @@ modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs) switch (name[3]) { case 'l': if (memEQ(name, "lvalue", 6)) { + if (!CvISXSUB(MUTABLE_CV(sv)) + && CvROOT(MUTABLE_CV(sv)) + && !CvLVALUE(MUTABLE_CV(sv)) != negated) + break; if (negated) CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE; else -- cgit v1.2.1