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 if (SvTYPE(sv) == SVt_PVGV) {
112 /* Hope this came from toke.c if not a GV. */
119 /* anything recognized had a 'continue' above */
129 /* package attributes; */
131 XS(XS_attributes_bootstrap)
134 char *file = __FILE__;
137 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
139 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
140 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
141 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
142 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
143 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
148 XS(XS_attributes__modify_attrs)
156 "Usage: attributes::_modify_attrs $reference, @attributes");
160 if (!(SvOK(rv) && SvROK(rv)))
164 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
169 XS(XS_attributes__fetch_attrs)
178 "Usage: attributes::_fetch_attrs $reference");
183 if (!(SvOK(rv) && SvROK(rv)))
187 switch (SvTYPE(sv)) {
189 cvflags = CvFLAGS((CV*)sv);
190 if (cvflags & CVf_LOCKED)
191 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
193 if (cvflags & CVf_LVALUE)
194 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
196 if (cvflags & CVf_METHOD)
197 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
198 if (GvUNIQUE(CvGV((CV*)sv)))
199 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
203 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
212 XS(XS_attributes__guess_stash)
219 SV * TARG = sv_newmortal();
225 "Usage: attributes::_guess_stash $reference");
230 if (!(SvOK(rv) && SvROK(rv)))
235 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
236 #if 0 /* this was probably a bad idea */
237 else if (SvPADMY(sv))
238 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
242 switch (SvTYPE(sv)) {
244 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
245 stash = GvSTASH(CvGV(sv));
246 else if (/* !CvANON(sv) && */ CvSTASH(sv))
250 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
254 if (GvGP(sv) && GvESTASH((GV*)sv))
255 stash = GvESTASH((GV*)sv);
261 sv_setpv(TARG, HvNAME(stash));
270 XS(XS_attributes_reftype)
277 SV * TARG = sv_newmortal();
283 "Usage: attributes::reftype $reference");
290 if (!(SvOK(rv) && SvROK(rv)))
293 sv_setpv(TARG, sv_reftype(sv, 0));
301 XS(XS_attributes__warn_reserved)
307 SV * TARG = sv_newmortal();
312 "Usage: attributes::_warn_reserved ()");
317 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);