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)) {
52 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
54 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
59 if (memEQ(name, "method", 6)) {
61 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
63 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
72 if (memEQs(name, 6, "shared")) {
74 Perl_croak(aTHX_ "A variable may not be unshared");
80 /* anything recognized had a 'continue' above */
88 MODULE = attributes PACKAGE = attributes
98 croak_xs_usage(cv, "@attributes");
102 if (!(SvOK(rv) && SvROK(rv)))
106 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
119 croak_xs_usage(cv, "$reference");
123 if (!(SvOK(rv) && SvROK(rv)))
127 switch (SvTYPE(sv)) {
129 cvflags = CvFLAGS((const CV *)sv);
130 if (cvflags & CVf_LVALUE)
131 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
132 if (cvflags & CVf_METHOD)
133 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
150 croak_xs_usage(cv, "$reference");
155 if (!(SvOK(rv) && SvROK(rv)))
160 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
161 #if 0 /* this was probably a bad idea */
162 else if (SvPADMY(sv))
163 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
166 const HV *stash = NULL;
167 switch (SvTYPE(sv)) {
169 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
170 stash = GvSTASH(CvGV(sv));
171 else if (/* !CvANON(sv) && */ CvSTASH(sv))
175 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
176 stash = GvESTASH(MUTABLE_GV(sv));
182 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
197 croak_xs_usage(cv, "$reference");
203 if (!(SvOK(rv) && SvROK(rv)))
206 sv_setpv(TARG, sv_reftype(sv, 0));
212 * c-indentation-style: bsd
214 * indent-tabs-mode: t
217 * ex: set ts=8 sts=4 sw=4 noet: