Subject: | delete old names for debugging purposes |
When a subroutine is renamed, %DB::sub has new entries added but old
ones not removed. That really messes up tab completion when code
heavily uses Sub::Name, e.g. via Method::Signatures.
diff --git Name.xs Name.xs
index f6d7bc2..656ae8d 100644
--- Name.xs
+++ Name.xs
@@ -7,6 +7,11 @@
#include "perl.h"
#include "XSUB.h"
+/* 5.8.8 is the first version with this, apparently */
+#ifndef SvPVX_const
+#define SvPVX_const(sv) ((const char *)SvPVX(sv))
+#endif
+
static MGVTBL subname_vtbl;
#ifndef PERL_MAGIC_ext
@@ -82,6 +87,19 @@ subname(name, sub)
mg->mg_flags |= MGf_REFCOUNTED;
mg->mg_obj = (SV *) gv;
SvRMAGICAL_on(cv);
+
+ if (PERLDB_SUBLINE && CvGV(cv) && isGV(CvGV(cv))) {
+ SV * const namesv = sv_newmortal();
+ SV *infosv;
+ gv_efullname3(namesv, CvGV(cv), NULL);
+ infosv = hv_delete(GvHV(PL_DBsub), SvPVX_const(namesv),
SvCUR(namesv), 0);
+ if (infosv) {
+ /* we use the gv's idea of its spelling, in case we call
subname again on the same CV */
+ gv_efullname3(namesv, gv, NULL);
+ (void)hv_store(GvHV(PL_DBsub), SvPVX_const(namesv),
SvCUR(namesv), SvREFCNT_inc(infosv), 0);
+ }
+ }
+
CvANON_off(cv);
#ifndef CvGV_set
CvGV(cv) = gv;