Sub-Identify
view release on metacpan or search on metacpan
Identify.xs view on Meta::CPAN
MODULE = Sub::Identify PACKAGE = Sub::Identify
PROTOTYPES: ENABLE
void
get_code_info(coderef)
SV* coderef
PREINIT:
char* name;
char* pkg;
PPCODE:
if (SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV) {
coderef = SvRV(coderef);
if (CvGV(coderef)) {
name = GvNAME( CvGV(coderef) );
pkg = HvNAME( GvSTASH(CvGV(coderef)) );
EXTEND(SP, 2);
PUSHs(sv_2mortal(newSVpvn(pkg, strlen(pkg))));
PUSHs(sv_2mortal(newSVpvn(name, strlen(name))));
}
else {
/* sub is being compiled: bail out and return nothing. */
}
}
void
get_code_location(coderef)
SV* coderef
PREINIT:
char* file;
line_t line;
PPCODE:
if (SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV) {
coderef = SvRV(coderef);
if (CvSTART(coderef) && !CvISXSUB(coderef)) {
file = CvFILE(coderef);
line = CopLINE((const COP*)CvSTART(coderef));
EXTEND(SP, 2);
PUSHs(sv_2mortal(newSVpvn(file, strlen(file))));
PUSHs(sv_2mortal(newSViv(line)));
}
}
( run in 0.473 second using v1.01-cache-2.11-cpan-5511b514fd6 )