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;
95 /* anything recognized had a 'continue' above */
105 /* package attributes; */
107 XS(XS_attributes_bootstrap)
110 char *file = __FILE__;
112 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
113 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
114 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
115 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
116 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
121 XS(XS_attributes__modify_attrs)
129 "Usage: attributes::_modify_attrs $reference, @attributes");
133 if (!(SvOK(rv) && SvROK(rv)))
137 XSRETURN(modify_SV_attributes(aTHXo_ sv, &ST(0), &ST(1), items-1));
142 XS(XS_attributes__fetch_attrs)
151 "Usage: attributes::_fetch_attrs $reference");
156 if (!(SvOK(rv) && SvROK(rv)))
160 switch (SvTYPE(sv)) {
162 cvflags = CvFLAGS((CV*)sv);
163 if (cvflags & CVf_LOCKED)
164 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
166 if (cvflags & CVf_LVALUE)
167 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
169 if (cvflags & CVf_METHOD)
170 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
179 XS(XS_attributes__guess_stash)
186 SV * TARG = sv_newmortal();
192 "Usage: attributes::_guess_stash $reference");
197 if (!(SvOK(rv) && SvROK(rv)))
202 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
203 #if 0 /* this was probably a bad idea */
204 else if (SvPADMY(sv))
205 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
209 switch (SvTYPE(sv)) {
211 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)) &&
212 HvNAME(GvSTASH(CvGV(sv))))
213 stash = GvSTASH(CvGV(sv));
214 else if (/* !CvANON(sv) && */ CvSTASH(sv) && HvNAME(CvSTASH(sv)))
218 if (!(SvFAKE(sv) && SvTIED_mg(sv, '*')))
222 if (GvGP(sv) && GvESTASH((GV*)sv) && HvNAME(GvESTASH((GV*)sv)))
223 stash = GvESTASH((GV*)sv);
229 sv_setpv(TARG, HvNAME(stash));
238 XS(XS_attributes_reftype)
245 SV * TARG = sv_newmortal();
251 "Usage: attributes::reftype $reference");
263 sv_setpv(TARG, sv_reftype(sv, 0));
271 XS(XS_attributes__warn_reserved)
278 SV * TARG = sv_newmortal();
283 "Usage: attributes::_warn_reserved ()");
288 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);