2 #define PERL_IN_XSUTILS_C
6 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
9 /* package attributes; */
10 void XS_attributes__warn_reserved(pTHXo_ CV *cv);
11 void XS_attributes_reftype(pTHXo_ CV *cv);
12 void XS_attributes__modify_attrs(pTHXo_ CV *cv);
13 void XS_attributes__guess_stash(pTHXo_ CV *cv);
14 void XS_attributes__fetch_attrs(pTHXo_ CV *cv);
15 void XS_attributes_bootstrap(pTHXo_ CV *cv);
19 * Note that only ${pkg}::bootstrap definitions should go here.
20 * This helps keep down the start-up time, which is especially
21 * relevant for users who don't invoke any features which are
22 * (partially) implemented here.
24 * The various bootstrap definitions can take care of doing
25 * package-specific newXS() calls. Since the layout of the
26 * bundled *.pm files is in a version-specific directory,
27 * version checks in these bootstrap calls are optional.
31 Perl_boot_core_xsutils(pTHX)
33 char *file = __FILE__;
35 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
41 modify_SV_attributes(pTHXo_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
49 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
50 name = SvPV(attr, len);
51 if ((negated = (*name == '-'))) {
62 if (strEQ(name, "lvalue")) {
64 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
66 CvFLAGS((CV*)sv) |= CVf_LVALUE;
69 #endif /* defined CVf_LVALUE */
70 if (strEQ(name, "locked")) {
72 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
74 CvFLAGS((CV*)sv) |= CVf_LOCKED;
79 if (strEQ(name, "method")) {
81 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
83 CvFLAGS((CV*)sv) |= CVf_METHOD;
88 if (strEQ(name, "shared")) {
90 GvSHARED_off(CvGV((CV*)sv));
92 GvSHARED_on(CvGV((CV*)sv));
105 if (strEQ(name, "shared")) {
106 /* toke.c has already marked as GvSHARED */
113 /* anything recognized had a 'continue' above */
123 /* package attributes; */
125 XS(XS_attributes_bootstrap)
128 char *file = __FILE__;
130 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
131 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
132 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
133 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
134 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
139 XS(XS_attributes__modify_attrs)
147 "Usage: attributes::_modify_attrs $reference, @attributes");
151 if (!(SvOK(rv) && SvROK(rv)))
155 XSRETURN(modify_SV_attributes(aTHXo_ sv, &ST(0), &ST(1), items-1));
160 XS(XS_attributes__fetch_attrs)
169 "Usage: attributes::_fetch_attrs $reference");
174 if (!(SvOK(rv) && SvROK(rv)))
178 switch (SvTYPE(sv)) {
180 cvflags = CvFLAGS((CV*)sv);
181 if (cvflags & CVf_LOCKED)
182 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
184 if (cvflags & CVf_LVALUE)
185 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
187 if (cvflags & CVf_METHOD)
188 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
189 if (GvSHARED(CvGV((CV*)sv)))
190 XPUSHs(sv_2mortal(newSVpvn("shared", 6)));
199 XS(XS_attributes__guess_stash)
206 SV * TARG = sv_newmortal();
212 "Usage: attributes::_guess_stash $reference");
217 if (!(SvOK(rv) && SvROK(rv)))
222 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
223 #if 0 /* this was probably a bad idea */
224 else if (SvPADMY(sv))
225 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
229 switch (SvTYPE(sv)) {
231 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)) &&
232 HvNAME(GvSTASH(CvGV(sv))))
233 stash = GvSTASH(CvGV(sv));
234 else if (/* !CvANON(sv) && */ CvSTASH(sv) && HvNAME(CvSTASH(sv)))
238 if (!(SvFAKE(sv) && SvTIED_mg(sv, '*')))
242 if (GvGP(sv) && GvESTASH((GV*)sv) && HvNAME(GvESTASH((GV*)sv)))
243 stash = GvESTASH((GV*)sv);
249 sv_setpv(TARG, HvNAME(stash));
258 XS(XS_attributes_reftype)
265 SV * TARG = sv_newmortal();
271 "Usage: attributes::reftype $reference");
278 if (!(SvOK(rv) && SvROK(rv)))
281 sv_setpv(TARG, sv_reftype(sv, 0));
289 XS(XS_attributes__warn_reserved)
295 SV * TARG = sv_newmortal();
300 "Usage: attributes::_warn_reserved ()");
305 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);