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;
75 if (memEQ(name, "share", 5)) {
77 Perl_croak(aTHX_ "A variable may not be unshared");
83 if (memEQ(name, "uniqu", 5)) {
84 if (isGV_with_GP(sv)) {
91 /* Hope this came from toke.c if not a GV. */
98 /* anything recognized had a 'continue' above */
106 MODULE = attributes PACKAGE = attributes
116 croak_xs_usage(cv, "@attributes");
120 if (!(SvOK(rv) && SvROK(rv)))
124 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
136 croak_xs_usage(cv, "$reference");
140 if (!(SvOK(rv) && SvROK(rv)))
144 switch (SvTYPE(sv)) {
146 cvflags = CvFLAGS((const CV *)sv);
147 if (cvflags & CVf_LOCKED)
148 XPUSHs(newSVpvs_flags("locked", SVs_TEMP));
149 if (cvflags & CVf_LVALUE)
150 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
151 if (cvflags & CVf_METHOD)
152 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
153 if (GvUNIQUE(CvGV((const CV *)sv)))
154 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
157 if (isGV_with_GP(sv) && GvUNIQUE(sv))
158 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
174 croak_xs_usage(cv, "$reference");
179 if (!(SvOK(rv) && SvROK(rv)))
184 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
185 #if 0 /* this was probably a bad idea */
186 else if (SvPADMY(sv))
187 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
190 const HV *stash = NULL;
191 switch (SvTYPE(sv)) {
193 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
194 stash = GvSTASH(CvGV(sv));
195 else if (/* !CvANON(sv) && */ CvSTASH(sv))
199 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
200 stash = GvESTASH(MUTABLE_GV(sv));
206 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
220 croak_xs_usage(cv, "$reference");
226 if (!(SvOK(rv) && SvROK(rv)))
229 sv_setpv(TARG, sv_reftype(sv, 0));
235 * c-indentation-style: bsd
237 * indent-tabs-mode: t
240 * ex: set ts=8 sts=4 sw=4 noet: