Perlのメソッド一覧
スタッシュを教えてもらったので書いてみる。
canで調べてるのと同じ感じに。
static PyObject * perl_get_methodsnames(Perl_Object *self, PyObject *args) { char *module; HV *stash; HE *entry; PyObject *res; if (!PyArg_ParseTuple(args, "s:Perl.get_methodnames", &module)) return NULL; PerlInterpreter * my_perl = self->perl; PERL_SET_CONTEXT(my_perl); res = PyList_New(0); stash = gv_stashpv(module, FALSE); if(stash){ hv_iterinit(stash); while((entry = hv_iternext(stash))){ I32 klen; char *name = hv_iterkey(entry, &klen); GV *gv = gv_fetchmethod_autoload(stash, name, FALSE); if(gv && isGV(gv)){ //printf("method_name:%s \n", name); PyObject *item = PyString_FromString(name); if(PyList_Append(res, item) < 0){ Py_DECREF(item); return NULL; } Py_DECREF(item); } } } return res; }
まあ最後はtupleにした方がよかったかな。