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)
34 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
36 const char *name = SvPV_const(attr, len);
37 const bool negated = (*name == '-');
47 if (memEQ(name, "const", 5)) {
51 const bool warn = (!CvANON(sv) || CvCLONED(sv))
63 if (memEQ(name, "lvalue", 6)) {
65 !CvISXSUB(MUTABLE_CV(sv))
66 && CvROOT(MUTABLE_CV(sv))
67 && !CvLVALUE(MUTABLE_CV(sv)) != negated;
69 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
71 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
77 if (memEQ(name, "method", 6)) {
79 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
81 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
88 if (len > 10 && memEQ(name, "prototype(", 10)) {
89 SV * proto = newSVpvn(name+10,len-11);
90 HEK *const hek = CvNAME_HEK((CV *)sv);
92 if (name[len-1] != ')')
93 Perl_croak(aTHX_ "Unterminated attribute parameter in attribute list");
95 subname = sv_2mortal(newSVhek(hek));
97 subname=(SV *)CvGV((const CV *)sv);
98 if (ckWARN(WARN_ILLEGALPROTO))
99 Perl_validate_proto(aTHX_ subname, proto, TRUE);
100 Perl_cv_ckproto_len_flags(aTHX_ (const CV *)sv,
105 sv_setpvn(MUTABLE_SV(sv), name+10, len-11);
106 if (SvUTF8(attr)) SvUTF8_on(MUTABLE_SV(sv));
113 if (memEQs(name, len, "shared")) {
115 Perl_croak(aTHX_ "A variable may not be unshared");
121 /* anything recognized had a 'continue' above */
129 MODULE = attributes PACKAGE = attributes
139 croak_xs_usage(cv, "@attributes");
143 if (!(SvOK(rv) && SvROK(rv)))
147 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
160 croak_xs_usage(cv, "$reference");
164 if (!(SvOK(rv) && SvROK(rv)))
168 switch (SvTYPE(sv)) {
170 cvflags = CvFLAGS((const CV *)sv);
171 if (cvflags & CVf_LVALUE)
172 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
173 if (cvflags & CVf_METHOD)
174 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
191 croak_xs_usage(cv, "$reference");
196 if (!(SvOK(rv) && SvROK(rv)))
201 Perl_sv_sethek(aTHX_ TARG, HvNAME_HEK(SvSTASH(sv)));
202 #if 0 /* this was probably a bad idea */
203 else if (SvPADMY(sv))
204 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
207 const HV *stash = NULL;
208 switch (SvTYPE(sv)) {
210 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
211 stash = GvSTASH(CvGV(sv));
212 else if (/* !CvANON(sv) && */ CvSTASH(sv))
216 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
217 stash = GvESTASH(MUTABLE_GV(sv));
223 Perl_sv_sethek(aTHX_ TARG, HvNAME_HEK(stash));
238 croak_xs_usage(cv, "$reference");
244 if (!(SvOK(rv) && SvROK(rv)))
247 sv_setpv(TARG, sv_reftype(sv, 0));
252 * ex: set ts=8 sts=4 sw=4 et: