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"]
20 #define PERL_IN_XSUTILS_C
24 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
27 /* package attributes; */
28 PERL_XS_EXPORT_C void XS_attributes_reftype(pTHX_ CV *cv);
29 PERL_XS_EXPORT_C void XS_attributes__modify_attrs(pTHX_ CV *cv);
30 PERL_XS_EXPORT_C void XS_attributes__guess_stash(pTHX_ CV *cv);
31 PERL_XS_EXPORT_C void XS_attributes__fetch_attrs(pTHX_ CV *cv);
32 PERL_XS_EXPORT_C void XS_attributes_bootstrap(pTHX_ CV *cv);
36 * Note that only ${pkg}::bootstrap definitions should go here.
37 * This helps keep down the start-up time, which is especially
38 * relevant for users who don't invoke any features which are
39 * (partially) implemented here.
41 * The various bootstrap definitions can take care of doing
42 * package-specific newXS() calls. Since the layout of the
43 * bundled *.pm files is in a version-specific directory,
44 * version checks in these bootstrap calls are optional.
47 static const char file[] = __FILE__;
50 Perl_boot_core_xsutils(pTHX)
52 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
58 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
64 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
66 const char *name = SvPV_const(attr, len);
67 const bool negated = (*name == '-');
79 if (memEQ(name, "lvalue", 6)) {
81 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
83 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
88 if (memEQ(name, "locked", 6)) {
90 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LOCKED;
92 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LOCKED;
97 if (memEQ(name, "method", 6)) {
99 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
101 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
114 if (memEQ(name, "share", 5)) {
116 Perl_croak(aTHX_ "A variable may not be unshared");
122 if (memEQ(name, "uniqu", 5)) {
123 if (isGV_with_GP(sv)) {
130 /* Hope this came from toke.c if not a GV. */
137 /* anything recognized had a 'continue' above */
147 /* package attributes; */
149 XS(XS_attributes_bootstrap)
155 croak_xs_usage(cv, "$module");
157 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
158 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
159 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
160 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
165 XS(XS_attributes__modify_attrs)
173 croak_xs_usage(cv, "@attributes");
177 if (!(SvOK(rv) && SvROK(rv)))
181 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
186 XS(XS_attributes__fetch_attrs)
195 croak_xs_usage(cv, "$reference");
200 if (!(SvOK(rv) && SvROK(rv)))
204 switch (SvTYPE(sv)) {
206 cvflags = CvFLAGS((const CV *)sv);
207 if (cvflags & CVf_LOCKED)
208 XPUSHs(newSVpvs_flags("locked", SVs_TEMP));
209 if (cvflags & CVf_LVALUE)
210 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
211 if (cvflags & CVf_METHOD)
212 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
213 if (GvUNIQUE(CvGV((const CV *)sv)))
214 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
217 if (isGV_with_GP(sv) && GvUNIQUE(sv))
218 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
227 XS(XS_attributes__guess_stash)
236 croak_xs_usage(cv, "$reference");
241 if (!(SvOK(rv) && SvROK(rv)))
246 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
247 #if 0 /* this was probably a bad idea */
248 else if (SvPADMY(sv))
249 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
252 const HV *stash = NULL;
253 switch (SvTYPE(sv)) {
255 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
256 stash = GvSTASH(CvGV(sv));
257 else if (/* !CvANON(sv) && */ CvSTASH(sv))
261 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
262 stash = GvESTASH(MUTABLE_GV(sv));
268 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
275 XS(XS_attributes_reftype)
284 croak_xs_usage(cv, "$reference");
290 if (!(SvOK(rv) && SvROK(rv)))
293 sv_setpv(TARG, sv_reftype(sv, 0));
301 * c-indentation-style: bsd
303 * indent-tabs-mode: t
306 * ex: set ts=8 sts=4 sw=4 noet: