From d2b55565cb3bbafd9923c9b67e021bcf09c7eaa7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 14 Nov 2010 13:25:57 -0600 Subject: implement get_all_symbols --- Stash.xs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'Stash.xs') diff --git a/Stash.xs b/Stash.xs index 41d9c0c..b0fe7c3 100644 --- a/Stash.xs +++ b/Stash.xs @@ -703,6 +703,55 @@ list_all_symbols(self, vartype=VAR_NONE) } } +void +get_all_symbols(self, vartype=VAR_NONE) + SV *self + vartype_t vartype + PREINIT: + HV *namespace, *ret; + SV *val; + char *key; + I32 len; + PPCODE: + namespace = _get_namespace(self); + ret = newHV(); + + hv_iterinit(namespace); + while ((val = hv_iternextsv(namespace, &key, &len))) { + GV *gv = (GV*)val; + + if (!isGV(gv)) + _expand_glob(self, key); + + switch (vartype) { + case VAR_SCALAR: + if (GvSVOK(val)) + hv_store(ret, key, len, newRV_inc(GvSV(gv)), 0); + break; + case VAR_ARRAY: + if (GvAVOK(val)) + hv_store(ret, key, len, newRV_inc((SV*)GvAV(gv)), 0); + break; + case VAR_HASH: + if (GvHVOK(val)) + hv_store(ret, key, len, newRV_inc((SV*)GvHV(gv)), 0); + break; + case VAR_CODE: + if (GvCVOK(val)) + hv_store(ret, key, len, newRV_inc((SV*)GvCV(gv)), 0); + break; + case VAR_IO: + if (GvIOOK(val)) + hv_store(ret, key, len, newRV_inc((SV*)GvIO(gv)), 0); + break; + case VAR_NONE: + hv_store(ret, key, len, SvREFCNT_inc_simple_NN(val), 0); + break; + } + } + + mPUSHs(newRV_noinc((SV*)ret)); + BOOT: { name_key = newSVpvs("name"); -- cgit v1.2.3-54-g00ecf