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(pTHX_ CV *cv);
11 void XS_attributes_reftype(pTHX_ CV *cv);
12 void XS_attributes__modify_attrs(pTHX_ CV *cv);
13 void XS_attributes__guess_stash(pTHX_ CV *cv);
14 void XS_attributes__fetch_attrs(pTHX_ CV *cv);
15 void XS_attributes_bootstrap(pTHX_ 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(pTHX_ 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, "unique")) {
90 GvUNIQUE_off(CvGV((CV*)sv));
92 GvUNIQUE_on(CvGV((CV*)sv));
105 if (strEQ(name, "unique")) {
106 /* toke.c has already marked as GVf_UNIQUE */
113 /* anything recognized had a 'continue' above */
123 /* package attributes; */
125 XS(XS_attributes_bootstrap)
128 char *file = __FILE__;
131 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
133 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
134 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
135 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
136 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
137 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
142 XS(XS_attributes__modify_attrs)
150 "Usage: attributes::_modify_attrs $reference, @attributes");
154 if (!(SvOK(rv) && SvROK(rv)))
158 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
163 XS(XS_attributes__fetch_attrs)
172 "Usage: attributes::_fetch_attrs $reference");
177 if (!(SvOK(rv) && SvROK(rv)))
181 switch (SvTYPE(sv)) {
183 cvflags = CvFLAGS((CV*)sv);
184 if (cvflags & CVf_LOCKED)
185 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
187 if (cvflags & CVf_LVALUE)
188 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
190 if (cvflags & CVf_METHOD)
191 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
192 if (GvUNIQUE(CvGV((CV*)sv)))
193 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
202 XS(XS_attributes__guess_stash)
209 SV * TARG = sv_newmortal();
215 "Usage: attributes::_guess_stash $reference");
220 if (!(SvOK(rv) && SvROK(rv)))
225 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
226 #if 0 /* this was probably a bad idea */
227 else if (SvPADMY(sv))
228 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
232 switch (SvTYPE(sv)) {
234 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
235 stash = GvSTASH(CvGV(sv));
236 else if (/* !CvANON(sv) && */ CvSTASH(sv))
240 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
244 if (GvGP(sv) && GvESTASH((GV*)sv))
245 stash = GvESTASH((GV*)sv);
251 sv_setpv(TARG, HvNAME(stash));
260 XS(XS_attributes_reftype)
267 SV * TARG = sv_newmortal();
273 "Usage: attributes::reftype $reference");
280 if (!(SvOK(rv) && SvROK(rv)))
283 sv_setpv(TARG, sv_reftype(sv, 0));
291 XS(XS_attributes__warn_reserved)
297 SV * TARG = sv_newmortal();
302 "Usage: attributes::_warn_reserved ()");
307 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);