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 !CvISXSUB(MUTABLE_CV(sv))
53 && CvROOT(MUTABLE_CV(sv))
54 && !CvLVALUE(MUTABLE_CV(sv)) != negated;
56 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
58 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
64 if (memEQ(name, "method", 6)) {
66 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
68 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
77 if (memEQs(name, 6, "shared")) {
79 Perl_croak(aTHX_ "A variable may not be unshared");
85 /* anything recognized had a 'continue' above */
93 MODULE = attributes PACKAGE = attributes
103 croak_xs_usage(cv, "@attributes");
107 if (!(SvOK(rv) && SvROK(rv)))
111 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
124 croak_xs_usage(cv, "$reference");
128 if (!(SvOK(rv) && SvROK(rv)))
132 switch (SvTYPE(sv)) {
134 cvflags = CvFLAGS((const CV *)sv);
135 if (cvflags & CVf_LVALUE)
136 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
137 if (cvflags & CVf_METHOD)
138 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
155 croak_xs_usage(cv, "$reference");
160 if (!(SvOK(rv) && SvROK(rv)))
165 Perl_sv_sethek(aTHX_ TARG, HvNAME_HEK(SvSTASH(sv)));
166 #if 0 /* this was probably a bad idea */
167 else if (SvPADMY(sv))
168 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
171 const HV *stash = NULL;
172 switch (SvTYPE(sv)) {
174 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
175 stash = GvSTASH(CvGV(sv));
176 else if (/* !CvANON(sv) && */ CvSTASH(sv))
180 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
181 stash = GvESTASH(MUTABLE_GV(sv));
187 Perl_sv_sethek(aTHX_ TARG, HvNAME_HEK(stash));
202 croak_xs_usage(cv, "$reference");
208 if (!(SvOK(rv) && SvROK(rv)))
211 sv_setpv(TARG, sv_reftype(sv, 0));
217 * c-indentation-style: bsd
219 * indent-tabs-mode: nil
222 * ex: set ts=8 sts=4 sw=4 et: