6 #define NEED_sv_2pv_flags
7 #define NEED_sv_2pv_nolen
17 U32 hash_package_name;
24 Pass in a coderef, returns:
25 [ $pkg_name, $coderef_name ] ie:
29 MODULE = Class::MOP PACKAGE = Class::MOP
32 key_name = newSVpvs("name");
33 key_body = newSVpvs("body");
34 key_package = newSVpvs("package");
35 key_package_name = newSVpvs("package_name");
37 PERL_HASH(hash_name, "name", 4);
38 PERL_HASH(hash_body, "body", 4);
39 PERL_HASH(hash_package, "package", 7);
40 PERL_HASH(hash_package_name, "package_name", 12);
47 get_code_info(coderef)
53 if( SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV){
54 coderef = SvRV(coderef);
55 /* I think this only gets triggered with a mangled coderef, but if
56 we hit it without the guard, we segfault. The slightly odd return
57 value strikes me as an improvement (mst)
60 if ( isGV_with_GP(CvGV(coderef))) {
62 pkg = HvNAME( GvSTASH(CvGV(coderef)) );
63 name = GvNAME( CvGV(coderef) );
72 PUSHs(newSVpvn(pkg, strlen(pkg)));
73 PUSHs(newSVpvn(name, strlen(name)));
77 MODULE = Class::MOP PACKAGE = Class::MOP::Package
80 get_all_package_symbols(self, ...)
85 SV *type_filter = NULL;
89 die("Cannot call get_all_package_symbols as a class method");
93 case G_VOID: return; break;
94 case G_SCALAR: ST(0) = &PL_sv_undef; return; break;
97 if ( items > 1 ) type_filter = ST(1);
101 if ((he = hv_fetch_ent((HV *)SvRV(self), key_package, 0, hash_package)))
102 stash = gv_stashsv(HeVAL(he),0);
106 (void)hv_iterinit(stash);
108 if ( type_filter && SvPOK(type_filter) ) {
109 const char *const type = SvPV_nolen(type_filter);
111 while ((he = hv_iternext(stash))) {
112 SV *const gv = HeVAL(he);
119 switch( SvTYPE(gv) ) {
122 case 'C': sv = (SV *)GvCVu(gv); break; /* CODE */
123 case 'A': sv = (SV *)GvAV(gv); break; /* ARRAY */
124 case 'I': sv = (SV *)GvIO(gv); break; /* IO */
125 case 'H': sv = (SV *)GvHV(gv); break; /* HASH */
126 case 'S': sv = (SV *)GvSV(gv); break; /* SCALAR */
128 croak("Unknown type %s\n", type);
132 /* BAH! constants are horrible */
138 /* we don't really care about the length,
139 but that's the API */
140 key = HePV(he, keylen);
141 package = HvNAME(stash);
142 fq = newSVpvf("%s::%s", package, key);
143 sv = (SV*)get_cv(SvPV_nolen(fq), 0);
150 SV *key = hv_iterkeysv(he);
154 PUSHs(sv_2mortal(newRV_inc(sv)));
159 EXTEND(SP, HvKEYS(stash) * 2);
161 while ((he = hv_iternext(stash))) {
162 SV *key = hv_iterkeysv(he);
180 die("Cannot call name as a class method");
183 if ((he = hv_fetch_ent((HV *)SvRV(self), key_package, 0, hash_package)))
186 ST(0) = &PL_sv_undef;
188 MODULE = Class::MOP PACKAGE = Class::MOP::Attribute
197 die("Cannot call name as a class method");
200 if ((he = hv_fetch_ent((HV *)SvRV(self), key_name, 0, hash_name)))
203 ST(0) = &PL_sv_undef;
205 MODULE = Class::MOP PACKAGE = Class::MOP::Method
214 die("Cannot call name as a class method");
217 if ((he = hv_fetch_ent((HV *)SvRV(self), key_name, 0, hash_name)))
220 ST(0) = &PL_sv_undef;
229 die("Cannot call package_name as a class method");
232 if ((he = hv_fetch_ent((HV *)SvRV(self), key_package_name, 0, hash_package_name)))
235 ST(0) = &PL_sv_undef;
244 die("Cannot call body as a class method");
247 if ((he = hv_fetch_ent((HV *)SvRV(self), key_body, 0, hash_body)))
250 ST(0) = &PL_sv_undef;