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 #define PERL_IN_XSUTILS_C
15 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
18 /* package attributes; */
19 void XS_attributes__warn_reserved(pTHX_ CV *cv);
20 void XS_attributes_reftype(pTHX_ CV *cv);
21 void XS_attributes__modify_attrs(pTHX_ CV *cv);
22 void XS_attributes__guess_stash(pTHX_ CV *cv);
23 void XS_attributes__fetch_attrs(pTHX_ CV *cv);
24 void XS_attributes_bootstrap(pTHX_ CV *cv);
28 * Note that only ${pkg}::bootstrap definitions should go here.
29 * This helps keep down the start-up time, which is especially
30 * relevant for users who don't invoke any features which are
31 * (partially) implemented here.
33 * The various bootstrap definitions can take care of doing
34 * package-specific newXS() calls. Since the layout of the
35 * bundled *.pm files is in a version-specific directory,
36 * version checks in these bootstrap calls are optional.
40 Perl_boot_core_xsutils(pTHX)
42 char *file = __FILE__;
44 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
50 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
58 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
59 name = SvPV(attr, len);
60 if ((negated = (*name == '-'))) {
71 if (strEQ(name, "lvalue")) {
73 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
75 CvFLAGS((CV*)sv) |= CVf_LVALUE;
78 #endif /* defined CVf_LVALUE */
79 if (strEQ(name, "locked")) {
81 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
83 CvFLAGS((CV*)sv) |= CVf_LOCKED;
88 if (strEQ(name, "method")) {
90 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
92 CvFLAGS((CV*)sv) |= CVf_METHOD;
97 if (strEQ(name, "unique")) {
99 GvUNIQUE_off(CvGV((CV*)sv));
101 GvUNIQUE_on(CvGV((CV*)sv));
114 if (strEQ(name, "unique")) {
115 if (SvTYPE(sv) == SVt_PVGV) {
121 /* Hope this came from toke.c if not a GV. */
128 /* anything recognized had a 'continue' above */
138 /* package attributes; */
140 XS(XS_attributes_bootstrap)
143 char *file = __FILE__;
146 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
148 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
149 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
150 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
151 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
152 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
157 XS(XS_attributes__modify_attrs)
165 "Usage: attributes::_modify_attrs $reference, @attributes");
169 if (!(SvOK(rv) && SvROK(rv)))
173 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
178 XS(XS_attributes__fetch_attrs)
187 "Usage: attributes::_fetch_attrs $reference");
192 if (!(SvOK(rv) && SvROK(rv)))
196 switch (SvTYPE(sv)) {
198 cvflags = CvFLAGS((CV*)sv);
199 if (cvflags & CVf_LOCKED)
200 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
202 if (cvflags & CVf_LVALUE)
203 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
205 if (cvflags & CVf_METHOD)
206 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
207 if (GvUNIQUE(CvGV((CV*)sv)))
208 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
212 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
221 XS(XS_attributes__guess_stash)
228 SV * TARG = sv_newmortal();
234 "Usage: attributes::_guess_stash $reference");
239 if (!(SvOK(rv) && SvROK(rv)))
244 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
245 #if 0 /* this was probably a bad idea */
246 else if (SvPADMY(sv))
247 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
251 switch (SvTYPE(sv)) {
253 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
254 stash = GvSTASH(CvGV(sv));
255 else if (/* !CvANON(sv) && */ CvSTASH(sv))
259 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
263 if (GvGP(sv) && GvESTASH((GV*)sv))
264 stash = GvESTASH((GV*)sv);
270 sv_setpv(TARG, HvNAME(stash));
279 XS(XS_attributes_reftype)
286 SV * TARG = sv_newmortal();
292 "Usage: attributes::reftype $reference");
299 if (!(SvOK(rv) && SvROK(rv)))
302 sv_setpv(TARG, sv_reftype(sv, 0));
310 XS(XS_attributes__warn_reserved)
316 SV * TARG = sv_newmortal();
321 "Usage: attributes::_warn_reserved ()");
326 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);