From: Vincent Pit Date: Sun, 25 Jul 2010 10:01:11 +0000 (+0200) Subject: Get rid of Symbol and delete the code slot in XS X-Git-Tag: v0.06~9 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=f3015fc0f10b75a7e7073d450605029e3cf83978;p=perl%2Fmodules%2Fsubs-auto.git Get rid of Symbol and delete the code slot in XS It's the only way we have to preserve the GV file name. --- diff --git a/MANIFEST b/MANIFEST index d86f980..6444beb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,6 +3,7 @@ MANIFEST META.yml Makefile.PL README +auto.xs lib/subs/auto.pm samples/subs.pl t/00-load.t diff --git a/Makefile.PL b/Makefile.PL index 7927178..ed2e049 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,8 +14,8 @@ $file = "lib/$file.pm"; my %PREREQ_PM = ( 'B::Keywords' => 0, 'Carp' => 0, - 'Symbol' => 0, 'Variable::Magic' => '0.08', + 'XSLoader' => 0, ); my %META = ( diff --git a/auto.xs b/auto.xs new file mode 100644 index 0000000..35439a0 --- /dev/null +++ b/auto.xs @@ -0,0 +1,24 @@ +/* This file is part of the subs::auto Perl module. + * See http://search.cpan.org/dist/subs-auto/ */ + +#define PERL_NO_GET_CONTEXT +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +MODULE = subs::auto PACKAGE = subs::auto + +PROTOTYPES: ENABLE + +void +_delete_sub(SV *fqn) +PREINIT: + GV *gv; +PPCODE: + gv = gv_fetchsv(fqn, 0, 0); + if (gv) { + CV *cv = GvCV(gv); + GvCV(gv) = NULL; + SvREFCNT_dec(cv); + } + XSRETURN(0); diff --git a/lib/subs/auto.pm b/lib/subs/auto.pm index 3cc549d..98b02e5 100644 --- a/lib/subs/auto.pm +++ b/lib/subs/auto.pm @@ -5,12 +5,6 @@ use 5.010; use strict; use warnings; -use B::Keywords; - -use Symbol qw/gensym/; - -use Variable::Magic qw/wizard cast dispell getdata/; - =head1 NAME subs::auto - Read barewords as subroutine names. @@ -21,7 +15,10 @@ Version 0.05 =cut -our $VERSION = '0.05'; +our $VERSION; +BEGIN { + $VERSION = '0.05'; +} =head1 SYNOPSIS @@ -62,11 +59,19 @@ This module is B a source filter. =cut +use B; + +use B::Keywords; + +use Variable::Magic qw/wizard cast dispell getdata/; + BEGIN { unless (Variable::Magic::VMG_UVAR) { require Carp; Carp::croak('uvar magic not available'); } + require XSLoader; + XSLoader::load(__PACKAGE__, $VERSION); } my %core; @@ -84,9 +89,8 @@ BEGIN { my $tag = wizard data => sub { \(my $data = _REFCNT_PLACEHOLDERS ? 2 : 1) }; sub _reset { - my ($pkg, $func) = @_; - my $fqn = join '::', @_; + my $cb = do { no strict 'refs'; no warnings 'once'; @@ -97,14 +101,7 @@ sub _reset { $$data--; return if $$data > 0; - no strict 'refs'; - my $sym = gensym; - for (qw/SCALAR ARRAY HASH IO FORMAT/) { - no warnings 'once'; - *$sym = *$fqn{$_} if defined *$fqn{$_} - } - undef *$fqn; - *$fqn = *$sym; + _delete_sub($fqn); } } @@ -236,12 +233,12 @@ You have to open global filehandles outside of the scope of this pragma if you w L 5.10.0. -L (standard since perl 5), L (since 5.002). - L with C magic enabled (this should be assured by the required perl version). L. +L (standard since perl 5), L (since 5.006). + =head1 AUTHOR Vincent Pit, C<< >>, L.