3 * Copyright (c) 1999-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Perilous to us all are the devices of an art deeper than we possess
12 * ourselves." --Gandalf
17 #define PERL_IN_XSUTILS_C
21 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
24 /* package attributes; */
25 void XS_attributes__warn_reserved(pTHX_ CV *cv);
26 void XS_attributes_reftype(pTHX_ CV *cv);
27 void XS_attributes__modify_attrs(pTHX_ CV *cv);
28 void XS_attributes__guess_stash(pTHX_ CV *cv);
29 void XS_attributes__fetch_attrs(pTHX_ CV *cv);
30 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.
46 Perl_boot_core_xsutils(pTHX)
48 char *file = __FILE__;
50 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
56 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
64 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
65 name = SvPV(attr, len);
66 if ((negated = (*name == '-'))) {
77 if (strEQ(name, "lvalue")) {
79 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
81 CvFLAGS((CV*)sv) |= CVf_LVALUE;
84 #endif /* defined CVf_LVALUE */
85 if (strEQ(name, "locked")) {
87 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
89 CvFLAGS((CV*)sv) |= CVf_LOCKED;
94 if (strEQ(name, "method")) {
96 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
98 CvFLAGS((CV*)sv) |= CVf_METHOD;
103 if (strEQ(name, "unique")) {
105 GvUNIQUE_off(CvGV((CV*)sv));
107 GvUNIQUE_on(CvGV((CV*)sv));
120 if (strEQ(name, "unique")) {
121 if (SvTYPE(sv) == SVt_PVGV) {
127 /* Hope this came from toke.c if not a GV. */
134 /* anything recognized had a 'continue' above */
144 /* package attributes; */
146 XS(XS_attributes_bootstrap)
149 char *file = __FILE__;
152 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
154 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
155 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
156 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
157 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
158 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
163 XS(XS_attributes__modify_attrs)
171 "Usage: attributes::_modify_attrs $reference, @attributes");
175 if (!(SvOK(rv) && SvROK(rv)))
179 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
184 XS(XS_attributes__fetch_attrs)
193 "Usage: attributes::_fetch_attrs $reference");
198 if (!(SvOK(rv) && SvROK(rv)))
202 switch (SvTYPE(sv)) {
204 cvflags = CvFLAGS((CV*)sv);
205 if (cvflags & CVf_LOCKED)
206 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
208 if (cvflags & CVf_LVALUE)
209 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
211 if (cvflags & CVf_METHOD)
212 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
213 if (GvUNIQUE(CvGV((CV*)sv)))
214 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
218 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
227 XS(XS_attributes__guess_stash)
234 SV * TARG = sv_newmortal();
240 "Usage: attributes::_guess_stash $reference");
245 if (!(SvOK(rv) && SvROK(rv)))
250 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
251 #if 0 /* this was probably a bad idea */
252 else if (SvPADMY(sv))
253 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
257 switch (SvTYPE(sv)) {
259 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
260 stash = GvSTASH(CvGV(sv));
261 else if (/* !CvANON(sv) && */ CvSTASH(sv))
265 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
269 if (GvGP(sv) && GvESTASH((GV*)sv))
270 stash = GvESTASH((GV*)sv);
276 sv_setpv(TARG, HvNAME(stash));
285 XS(XS_attributes_reftype)
292 SV * TARG = sv_newmortal();
298 "Usage: attributes::reftype $reference");
305 if (!(SvOK(rv) && SvROK(rv)))
308 sv_setpv(TARG, sv_reftype(sv, 0));
316 XS(XS_attributes__warn_reserved)
322 SV * TARG = sv_newmortal();
327 "Usage: attributes::_warn_reserved ()");
332 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);