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 lib/*.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);
40 #endif /* PERL_OBJECT */
45 modify_SV_attributes(pTHXo_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
53 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
54 name = SvPV(attr, len);
55 if (negated = (*name == '-')) {
66 if (strEQ(name, "lvalue")) {
68 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
70 CvFLAGS((CV*)sv) |= CVf_LVALUE;
73 #endif /* defined CVf_LVALUE */
74 if (strEQ(name, "locked")) {
76 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
78 CvFLAGS((CV*)sv) |= CVf_LOCKED;
83 if (strEQ(name, "method")) {
85 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
87 CvFLAGS((CV*)sv) |= CVf_METHOD;
99 /* anything recognized had a 'continue' above */
109 /* package attributes; */
111 XS(XS_attributes_bootstrap)
114 char *file = __FILE__;
116 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
117 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
118 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
119 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
120 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
125 XS(XS_attributes__modify_attrs)
133 "Usage: attributes::_modify_attrs $reference, @attributes");
137 if (!(SvOK(rv) && SvROK(rv)))
141 XSRETURN(modify_SV_attributes(aTHXo_ sv, &ST(0), &ST(1), items-1));
146 XS(XS_attributes__fetch_attrs)
155 "Usage: attributes::_fetch_attrs $reference");
160 if (!(SvOK(rv) && SvROK(rv)))
164 switch (SvTYPE(sv)) {
166 cvflags = CvFLAGS((CV*)sv);
167 if (cvflags & CVf_LOCKED)
168 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
170 if (cvflags & CVf_LVALUE)
171 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
173 if (cvflags & CVf_METHOD)
174 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
183 XS(XS_attributes__guess_stash)
190 SV * TARG = sv_newmortal();
196 "Usage: attributes::_guess_stash $reference");
201 if (!(SvOK(rv) && SvROK(rv)))
206 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
207 #if 0 /* this was probably a bad idea */
208 else if (SvPADMY(sv))
209 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
213 switch (SvTYPE(sv)) {
215 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)) &&
216 HvNAME(GvSTASH(CvGV(sv))))
217 stash = GvSTASH(CvGV(sv));
218 else if (/* !CvANON(sv) && */ CvSTASH(sv) && HvNAME(CvSTASH(sv)))
222 if (!(SvFAKE(sv) && SvTIED_mg(sv, '*')))
226 if (GvGP(sv) && GvESTASH((GV*)sv) && HvNAME(GvESTASH((GV*)sv)))
227 stash = GvESTASH((GV*)sv);
233 sv_setpv(TARG, HvNAME(stash));
242 XS(XS_attributes_reftype)
249 SV * TARG = sv_newmortal();
255 "Usage: attributes::reftype $reference");
267 sv_setpv(TARG, sv_reftype(sv, 0));
275 XS(XS_attributes__warn_reserved)
282 SV * TARG = sv_newmortal();
287 "Usage: attributes::_warn_reserved ()");
292 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);