Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
138 lines (119 sloc) 3.64 KB
#ifndef __MOP_PACKAGE_C__
#define __MOP_PACKAGE_C__
#include "mop.h"
int
mop_package_get_code_info (SV *coderef, char **pkg, char **name)
{
coderef = (CV *) coderef;
/*
if (! SvOK(coderef)) {
MRO_DEBUG("SvOK failed on coderef");
return 0;
}
if (! SvROK(coderef)) {
MRO_DEBUG("SvROK failed on coderef");
return 0;
}
if (SvTYPE(SvRV(coderef)) != SVt_PVCV) {
MRO_DEBUG("SvTYPE(SvRV) failed on coderef");
return 0;
}
coderef = SvRV(coderef);
* sub is still being compiled *
if (!CvGV(coderef)) {
return 0;
}
*/
/* I think this only gets triggered with a mangled coderef, but if
we hit it without the guard, we segfault. The slightly odd return
value strikes me as an improvement (mst)
*/
#ifdef isGV_with_GP
if ( isGV_with_GP(CvGV(coderef)) ) {
#endif
*pkg = HvNAME( GvSTASH(CvGV(coderef)) );
*name = GvNAME( CvGV(coderef) );
#ifdef isGV_with_GP
} else {
*pkg = "__UNKNOWN__";
*name = "__ANON__";
}
#endif
return 1;
}
void
mop_package_get_package_symbols (
HV *stash,
mop_package_type_filter_t filter,
mop_package_symbols_cb_t cb,
void *ud
) {
HE *he;
MOP_DEBUG( "mop_package_get_package_symbols for %s\n", HvNAME(stash) );
(void)hv_iterinit(stash);
if (filter == TYPE_FILTER_NONE) {
while ( (he = hv_iternext(stash)) ) {
STRLEN keylen;
const char *key = HePV(he, keylen);
if (!cb(key, keylen, HeVAL(he), ud)) {
return;
}
}
return;
}
while ( (he = hv_iternext(stash)) ) {
SV *const gv = HeVAL(he);
SV *sv = NULL;
char *key;
STRLEN keylen;
char *package;
SV *fq;
MOP_DEBUG( "Checking val = %s\n", GvNAME(gv));
switch( SvTYPE(gv) ) {
#ifndef SVt_RV
case SVt_RV:
#endif
case SVt_PV:
case SVt_IV:
/* expand the gv into a real typeglob if it
* contains stub functions and we were asked to
* return CODE symbols */
if (filter == TYPE_FILTER_CODE) {
if (SvROK(gv)) {
/* we don't really care about the length,
but that's the API */
key = HePV(he, keylen);
package = HvNAME(stash);
fq = newSVpvf("%s::%s", package, key);
sv = (SV *)get_cv(SvPV_nolen(fq), 0);
break;
}
key = HePV(he, keylen);
gv_init((GV *)gv, stash, key, keylen, GV_ADDMULTI);
}
/* fall through */
case SVt_PVGV:
MOP_DEBUG("Checking for other stuff\n");
switch (filter) {
case TYPE_FILTER_CODE: sv = (SV *)GvCVu(gv); break;
case TYPE_FILTER_ARRAY: sv = (SV *)GvAV(gv); break;
case TYPE_FILTER_IO: sv = (SV *)GvIO(gv); break;
case TYPE_FILTER_HASH: sv = (SV *)GvHV(gv); break;
case TYPE_FILTER_SCALAR: sv = (SV *)GvSV(gv); break;
default:
croak("Unknown type");
}
break;
default:
continue;
}
if (sv) {
const char *key = HePV(he, keylen);
MOP_DEBUG("Handing SV to callback");
if (!cb(key, keylen, sv, ud)) {
return;
}
}
}
}
#endif /* __MOP_PACKAGE_C__ */
Something went wrong with that request. Please try again.