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"]
24 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
28 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
34 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
36 const char *name = SvPV_const(attr, len);
37 const bool negated = (*name == '-');
49 if (memEQ(name, "lvalue", 6)) {
51 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
53 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
58 if (memEQ(name, "method", 6)) {
60 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
62 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
71 if (memEQs(name, 6, "shared")) {
73 Perl_croak(aTHX_ "A variable may not be unshared");
79 /* anything recognized had a 'continue' above */
87 MODULE = attributes PACKAGE = attributes
97 croak_xs_usage(cv, "@attributes");
101 if (!(SvOK(rv) && SvROK(rv)))
105 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
118 croak_xs_usage(cv, "$reference");
122 if (!(SvOK(rv) && SvROK(rv)))
126 switch (SvTYPE(sv)) {
128 cvflags = CvFLAGS((const CV *)sv);
129 if (cvflags & CVf_LVALUE)
130 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
131 if (cvflags & CVf_METHOD)
132 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
149 croak_xs_usage(cv, "$reference");
154 if (!(SvOK(rv) && SvROK(rv)))
159 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
160 #if 0 /* this was probably a bad idea */
161 else if (SvPADMY(sv))
162 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
165 const HV *stash = NULL;
166 switch (SvTYPE(sv)) {
168 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
169 stash = GvSTASH(CvGV(sv));
170 else if (/* !CvANON(sv) && */ CvSTASH(sv))
174 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
175 stash = GvESTASH(MUTABLE_GV(sv));
181 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
196 croak_xs_usage(cv, "$reference");
202 if (!(SvOK(rv) && SvROK(rv)))
205 sv_setpv(TARG, sv_reftype(sv, 0));
211 * c-indentation-style: bsd
213 * indent-tabs-mode: t
216 * ex: set ts=8 sts=4 sw=4 noet: