From: Jesse Luehrs Date: Fri, 12 Nov 2010 20:21:02 +0000 (-0600) Subject: expand constant stash entries on get X-Git-Tag: 0.14~51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb4df463eddfb4fb9b4090e43a860a2722ae6d34;p=gitmo%2FPackage-Stash-XS.git expand constant stash entries on get --- diff --git a/Stash.xs b/Stash.xs index db517d9..aefe1b1 100644 --- a/Stash.xs +++ b/Stash.xs @@ -394,6 +394,7 @@ get_package_symbol(self, variable, ...) PREINIT: HV *namespace; SV **entry; + GV *glob; CODE: namespace = _get_namespace(self); @@ -419,29 +420,38 @@ get_package_symbol(self, variable, ...) if (!entry) XSRETURN_UNDEF; - if (isGV(*entry)) { - GV *glob = (GV*)(*entry); - switch (variable.type) { - case VAR_SCALAR: - RETVAL = newRV(GvSV(glob)); - break; - case VAR_ARRAY: - RETVAL = newRV((SV*)GvAV(glob)); - break; - case VAR_HASH: - RETVAL = newRV((SV*)GvHV(glob)); - break; - case VAR_CODE: - RETVAL = newRV((SV*)GvCV(glob)); - break; - case VAR_IO: - RETVAL = newRV((SV*)GvIO(glob)); - break; - } + glob = (GV*)(*entry); + + if (!isGV(*entry)) { + SV *namesv; + char *name; + int len; + + namesv = newSVsv(_get_name(self)); + sv_catpvs(namesv, "::"); + sv_catpv(namesv, variable.name); + + name = SvPV(namesv, len); + + gv_init(glob, namespace, name, len, 1); } - else { - /* XXX: need to expand code slots */ - XSRETURN_UNDEF; + + switch (variable.type) { + case VAR_SCALAR: + RETVAL = newRV(GvSV(glob)); + break; + case VAR_ARRAY: + RETVAL = newRV((SV*)GvAV(glob)); + break; + case VAR_HASH: + RETVAL = newRV((SV*)GvHV(glob)); + break; + case VAR_CODE: + RETVAL = newRV((SV*)GvCV(glob)); + break; + case VAR_IO: + RETVAL = newRV((SV*)GvIO(glob)); + break; } OUTPUT: RETVAL diff --git a/t/07-edge-cases.t b/t/07-edge-cases.t index a742c76..e5928a5 100755 --- a/t/07-edge-cases.t +++ b/t/07-edge-cases.t @@ -39,4 +39,7 @@ ok(!$stash->has_package_symbol('$added'), '$added'); ok(!$stash->has_package_symbol('@added'), '@added'); ok($stash->has_package_symbol('%added'), '%added'); +my $constant = $stash->get_package_symbol('&FOO'); +is(ref($constant), 'CODE', "expanded a constant into a coderef"); + done_testing;