3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 * by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * 'Perilous to us all are the devices of an art deeper than we possess
13 * ourselves.' --Gandalf
15 * [p.597 of _The Lord of the Rings_, III/xi: "The PalantÃr"]
18 #define PERL_NO_GET_CONTEXT
25 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
29 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
35 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
37 const char *name = SvPV_const(attr, len);
38 const bool negated = (*name == '-');
50 if (memEQ(name, "lvalue", 6)) {
51 if (!CvISXSUB(MUTABLE_CV(sv))
52 && CvROOT(MUTABLE_CV(sv))
53 && !CvLVALUE(MUTABLE_CV(sv)) != negated)
56 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
58 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
63 if (memEQ(name, "method", 6)) {
65 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
67 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
76 if (memEQs(name, 6, "shared")) {
78 Perl_croak(aTHX_ "A variable may not be unshared");
84 /* anything recognized had a 'continue' above */
92 MODULE = attributes PACKAGE = attributes
102 croak_xs_usage(cv, "@attributes");
106 if (!(SvOK(rv) && SvROK(rv)))
110 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
123 croak_xs_usage(cv, "$reference");
127 if (!(SvOK(rv) && SvROK(rv)))
131 switch (SvTYPE(sv)) {
133 cvflags = CvFLAGS((const CV *)sv);
134 if (cvflags & CVf_LVALUE)
135 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
136 if (cvflags & CVf_METHOD)
137 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
154 croak_xs_usage(cv, "$reference");
159 if (!(SvOK(rv) && SvROK(rv)))
164 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
165 #if 0 /* this was probably a bad idea */
166 else if (SvPADMY(sv))
167 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
170 const HV *stash = NULL;
171 switch (SvTYPE(sv)) {
173 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
174 stash = GvSTASH(CvGV(sv));
175 else if (/* !CvANON(sv) && */ CvSTASH(sv))
179 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
180 stash = GvESTASH(MUTABLE_GV(sv));
186 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
201 croak_xs_usage(cv, "$reference");
207 if (!(SvOK(rv) && SvROK(rv)))
210 sv_setpv(TARG, sv_reftype(sv, 0));
216 * c-indentation-style: bsd
218 * indent-tabs-mode: t
221 * ex: set ts=8 sts=4 sw=4 noet: