summaryrefslogtreecommitdiff
path: root/ext/Tie-Hash-NamedCapture
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-03-08 17:33:39 +0000
committerNicholas Clark <nick@ccl4.org>2011-03-08 17:33:39 +0000
commit4b5ae309d8932eb959b5fc621604614358181bc9 (patch)
treee7642f4b976009cdcc21a5f4a6c1d19052406d38 /ext/Tie-Hash-NamedCapture
parentf8088870d3cebbc655e7ab8ab4e3f997db4e0fbe (diff)
downloadperl-4b5ae309d8932eb959b5fc621604614358181bc9.tar.gz
In Tie::Hash::NamedCapture move the tie of %+ and %- from perl to XS.
Diffstat (limited to 'ext/Tie-Hash-NamedCapture')
-rw-r--r--ext/Tie-Hash-NamedCapture/NamedCapture.pm9
-rw-r--r--ext/Tie-Hash-NamedCapture/NamedCapture.xs18
2 files changed, 19 insertions, 8 deletions
diff --git a/ext/Tie-Hash-NamedCapture/NamedCapture.pm b/ext/Tie-Hash-NamedCapture/NamedCapture.pm
index db86908a49..932e4404d1 100644
--- a/ext/Tie-Hash-NamedCapture/NamedCapture.pm
+++ b/ext/Tie-Hash-NamedCapture/NamedCapture.pm
@@ -3,15 +3,8 @@ package Tie::Hash::NamedCapture;
our $VERSION = "0.08";
-sub TIEHASH;
-
require XSLoader;
-XSLoader::load();
-
-tie %+, __PACKAGE__;
-tie %-, __PACKAGE__, all => 1;
-
-1;
+XSLoader::load(); # This returns true, which makes require happy.
__END__
diff --git a/ext/Tie-Hash-NamedCapture/NamedCapture.xs b/ext/Tie-Hash-NamedCapture/NamedCapture.xs
index 73deacdc1b..459a9984f8 100644
--- a/ext/Tie-Hash-NamedCapture/NamedCapture.xs
+++ b/ext/Tie-Hash-NamedCapture/NamedCapture.xs
@@ -15,9 +15,27 @@
#define EXISTS_ALIAS (RXapif_EXISTS | (2 << EXPECT_SHIFT))
#define SCALAR_ALIAS (RXapif_SCALAR | (1 << EXPECT_SHIFT))
+static
+tie_it(pTHX_ const char name, UV flag)
+{
+ GV *const gv = gv_fetchpvn(&name, 1, GV_ADDMULTI|GV_NOTQUAL, SVt_PVHV);
+ HV *const hv = GvHV(gv);
+ SV *rv = newSV_type(SVt_RV);
+
+ sv_setuv(newSVrv(rv, "Tie::Hash::NamedCapture"), flag);
+
+ sv_unmagic((SV *)hv, PERL_MAGIC_tied);
+ sv_magic((SV *)hv, rv, PERL_MAGIC_tied, NULL, 0);
+ SvREFCNT_dec(rv); /* As sv_magic increased it by one. */
+}
+
MODULE = Tie::Hash::NamedCapture PACKAGE = Tie::Hash::NamedCapture
PROTOTYPES: DISABLE
+BOOT:
+ tie_it(aTHX_ '-', RXapif_ALL);
+ tie_it(aTHX_ '+', RXapif_ONE);
+
SV *
TIEHASH(package, ...)
const char *package;