6 #define NEED_sv_2pv_flags
7 #define NEED_sv_2pv_nolen
21 Pass in a coderef, returns:
22 [ $pkg_name, $coderef_name ] ie:
26 MODULE = Class::MOP PACKAGE = Class::MOP
29 key_name = newSVpvs("name");
30 key_body = newSVpvs("body");
31 key_package = newSVpvs("package");
33 PERL_HASH(hash_name, "name", 4);
34 PERL_HASH(hash_body, "body", 4);
35 PERL_HASH(hash_package, "package", 7);
42 get_code_info(coderef)
48 if( SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV){
49 coderef = SvRV(coderef);
50 /* I think this only gets triggered with a mangled coderef, but if
51 we hit it without the guard, we segfault. The slightly odd return
52 value strikes me as an improvement (mst)
55 if ( isGV_with_GP(CvGV(coderef))) {
57 pkg = HvNAME( GvSTASH(CvGV(coderef)) );
58 name = GvNAME( CvGV(coderef) );
67 PUSHs(newSVpvn(pkg, strlen(pkg)));
68 PUSHs(newSVpvn(name, strlen(name)));
72 MODULE = Class::MOP PACKAGE = Class::MOP::Package
75 get_all_package_symbols(self, ...)
80 SV *type_filter = NULL;
85 case G_VOID: return; break;
86 case G_SCALAR: ST(0) = &PL_sv_undef; return; break;
89 if ( items > 1 ) type_filter = ST(1);
93 if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_package, 0, hash_package)))
94 stash = gv_stashsv(HeVAL(he),0);
98 (void)hv_iterinit(stash);
100 if ( type_filter && SvPOK(type_filter) ) {
101 const char *const type = SvPV_nolen(type_filter);
103 while ((he = hv_iternext(stash))) {
104 SV *const gv = HeVAL(he);
111 switch( SvTYPE(gv) ) {
114 case 'C': sv = (SV *)GvCVu(gv); break; /* CODE */
115 case 'A': sv = (SV *)GvAV(gv); break; /* ARRAY */
116 case 'I': sv = (SV *)GvIO(gv); break; /* IO */
117 case 'H': sv = (SV *)GvHV(gv); break; /* HASH */
118 case 'S': sv = (SV *)GvSV(gv); break; /* SCALAR */
120 croak("Unknown type %s\n", type);
124 /* BAH! constants are horrible */
126 /* we don't really care about the length,
127 but that's the API */
128 key = HePV(he, keylen);
129 package = HvNAME(stash);
130 fq = newSVpvf("%s::%s", package, key);
131 sv = sv_2mortal((SV*)get_cv(SvPV_nolen(fq), 0));
138 SV *key = hv_iterkeysv(he);
142 PUSHs(sv_2mortal(newRV_inc(sv)));
147 EXTEND(SP, HvKEYS(stash) * 2);
149 while ((he = hv_iternext(stash))) {
150 SV *key = hv_iterkeysv(he);
167 if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_package, 0, hash_package)))
170 ST(0) = &PL_sv_undef;
172 MODULE = Class::MOP PACKAGE = Class::Attribute
180 if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_name, 0, hash_name)))
183 ST(0) = &PL_sv_undef;
185 MODULE = Class::MOP PACKAGE = Class::Method
193 if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_name, 0, hash_name)))
196 ST(0) = &PL_sv_undef;
204 if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_body, 0, hash_body)))
207 ST(0) = &PL_sv_undef;