3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
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
18 #define PERL_IN_XSUTILS_C
22 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
25 /* package attributes; */
26 PERL_XS_EXPORT_C void XS_attributes_reftype(pTHX_ CV *cv);
27 PERL_XS_EXPORT_C void XS_attributes__modify_attrs(pTHX_ CV *cv);
28 PERL_XS_EXPORT_C void XS_attributes__guess_stash(pTHX_ CV *cv);
29 PERL_XS_EXPORT_C void XS_attributes__fetch_attrs(pTHX_ CV *cv);
30 PERL_XS_EXPORT_C void XS_attributes_bootstrap(pTHX_ CV *cv);
34 * Note that only ${pkg}::bootstrap definitions should go here.
35 * This helps keep down the start-up time, which is especially
36 * relevant for users who don't invoke any features which are
37 * (partially) implemented here.
39 * The various bootstrap definitions can take care of doing
40 * package-specific newXS() calls. Since the layout of the
41 * bundled *.pm files is in a version-specific directory,
42 * version checks in these bootstrap calls are optional.
45 static const char file[] = __FILE__;
48 Perl_boot_core_xsutils(pTHX)
50 newXS("attributes::bootstrap", XS_attributes_bootstrap, (char *)file);
56 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
61 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
63 const char *name = SvPV_const(attr, len);
64 const bool negated = (*name == '-');
75 if (memEQ(name, "assertion", 9)) {
77 CvFLAGS((CV*)sv) &= ~CVf_ASSERTION;
79 CvFLAGS((CV*)sv) |= CVf_ASSERTION;
88 if (memEQ(name, "lvalue", 6)) {
90 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
92 CvFLAGS((CV*)sv) |= CVf_LVALUE;
98 if (memEQ(name, "locked", 6)) {
100 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
102 CvFLAGS((CV*)sv) |= CVf_LOCKED;
107 if (memEQ(name, "method", 6)) {
109 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
111 CvFLAGS((CV*)sv) |= CVf_METHOD;
124 if (memEQ(name, "share", 5)) {
126 Perl_croak(aTHX_ "A variable may not be unshared");
132 if (memEQ(name, "uniqu", 5)) {
133 if (SvTYPE(sv) == SVt_PVGV) {
140 /* Hope this came from toke.c if not a GV. */
147 /* anything recognized had a 'continue' above */
157 /* package attributes; */
159 XS(XS_attributes_bootstrap)
164 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
166 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, (char *)file);
167 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, (char *)file, "$");
168 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, (char *)file, "$");
169 newXSproto("attributes::reftype", XS_attributes_reftype, (char *)file, "$");
174 XS(XS_attributes__modify_attrs)
182 "Usage: attributes::_modify_attrs $reference, @attributes");
186 if (!(SvOK(rv) && SvROK(rv)))
190 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
195 XS(XS_attributes__fetch_attrs)
204 "Usage: attributes::_fetch_attrs $reference");
209 if (!(SvOK(rv) && SvROK(rv)))
213 switch (SvTYPE(sv)) {
215 cvflags = CvFLAGS((CV*)sv);
216 if (cvflags & CVf_LOCKED)
217 XPUSHs(sv_2mortal(newSVpvs("locked")));
219 if (cvflags & CVf_LVALUE)
220 XPUSHs(sv_2mortal(newSVpvs("lvalue")));
222 if (cvflags & CVf_METHOD)
223 XPUSHs(sv_2mortal(newSVpvs("method")));
224 if (GvUNIQUE(CvGV((CV*)sv)))
225 XPUSHs(sv_2mortal(newSVpvs("unique")));
229 XPUSHs(sv_2mortal(newSVpvs("unique")));
238 XS(XS_attributes__guess_stash)
247 "Usage: attributes::_guess_stash $reference");
252 if (!(SvOK(rv) && SvROK(rv)))
257 sv_setpv(TARG, HvNAME_get(SvSTASH(sv)));
258 #if 0 /* this was probably a bad idea */
259 else if (SvPADMY(sv))
260 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
263 const HV *stash = NULL;
264 switch (SvTYPE(sv)) {
266 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
267 stash = GvSTASH(CvGV(sv));
268 else if (/* !CvANON(sv) && */ CvSTASH(sv))
272 if (GvGP(sv) && GvESTASH((GV*)sv))
273 stash = GvESTASH((GV*)sv);
279 sv_setpv(TARG, HvNAME_get(stash));
286 XS(XS_attributes_reftype)
295 "Usage: attributes::reftype $reference");
301 if (!(SvOK(rv) && SvROK(rv)))
304 sv_setpv(TARG, sv_reftype(sv, 0));
312 * c-indentation-style: bsd
314 * indent-tabs-mode: t
317 * ex: set ts=8 sts=4 sw=4 noet: