From: Leon Timmermans Date: Sun, 19 Jun 2016 18:35:39 +0000 (+0200) Subject: Look up stashes containing single-quotes correctly X-Git-Tag: v0.16~6^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12e89eea3db148bcfcb9521f5439b26fce258c58;p=p5sagit%2FSub-Name.git Look up stashes containing single-quotes correctly --- diff --git a/Name.xs b/Name.xs index 58342a9..10a8cd2 100644 --- a/Name.xs +++ b/Name.xs @@ -37,11 +37,12 @@ subname(name, sub) CV *cv = NULL; GV *gv; HV *stash = CopSTASH(PL_curcop); - const char *s, *end = NULL; + const char *s, *end = NULL, *begin = NULL; MAGIC *mg; STRLEN namelen; int utf8flag = SvUTF8(name); const char* nameptr = SvPV(name, namelen); + int seen_quote = 0, need_subst = 0; PPCODE: if (!SvROK(sub) && SvGMAGICAL(sub)) mg_get(sub); @@ -62,16 +63,43 @@ subname(name, sub) croak("Not a subroutine reference"); for (s = nameptr; s <= nameptr + namelen; s++) { - if (*s == ':' && s[-1] == ':') - end = ++s; - else if (*s && s[-1] == '\'') - end = s; + if (*s == ':' && s[-1] == ':') { + end = s - 1; + begin = ++s; + if (seen_quote) + seen_quote++; + } + else if (*s && s[-1] == '\'') { + end = s - 1; + begin = s; + seen_quote++; + } } s--; if (end) { - stash = GvHV(gv_fetchpvn_flags(nameptr, end - nameptr, GV_ADD | utf8flag, SVt_PVHV)); - nameptr = end; - namelen -= end - nameptr; + SV* tmp; + if (seen_quote > 1) { + STRLEN length = end - nameptr + seen_quote; + char* left; + int i, j; + tmp = newSV(length); + left = SvPVX(tmp); + for (i = 0, j = 0; j <= end - nameptr; ++i, ++j) { + if (nameptr[j] == '\'') { + left[i] = ':'; + left[++i] = ':'; + } + else { + left[i] = nameptr[j]; + } + } + stash = gv_stashpvn(left, i - 2, GV_ADD | utf8flag); + SvREFCNT_dec(tmp); + } + else + stash = gv_stashpvn(nameptr, end - nameptr, GV_ADD | utf8flag); + nameptr = begin; + namelen -= begin - nameptr; } #ifdef PERL_VERSION < 10