From: Peter Rabbitson Date: Sun, 27 Sep 2015 15:29:43 +0000 (+0200) Subject: Add an once-and-for-all workaround for Package::Stash::XS + =< 5.8.6 X-Git-Tag: 0.26~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=acb1d694099cd97960f4e1a81693e42bb91e4bbe;p=p5sagit%2Fnamespace-clean.git Add an once-and-for-all workaround for Package::Stash::XS + =< 5.8.6 The simple workaround in ac5c00e9 got broken by P::S::XS 0.36. Since at this point this is more or less a pattern, add a ridiculous-ish workaround forcing Package::Stash::PP-only on perls under 5.8.7. While not ideal, the benefits of ::XS are virtually invisible in this use case and moreover there is work underway to fix ::XS once and for all. Thus the commit is considered a viable temporary measure to stave off further errors. --- diff --git a/Changes b/Changes index cccc00c..4abca90 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ + - Exclusively use Package::Stash::PP on perls < 5.8.7 until a fixed + Package::Stash::XS ships - breakage keeps getting reintroduced + ( RT#107343, RT#74151 ) + [0.25] - Fix incorrect ExtUtils::CBuilder detection routine leading to Makefile.PL crashes when EU::CB is not available diff --git a/lib/namespace/clean.pm b/lib/namespace/clean.pm index b47a68e..9a2a0d6 100644 --- a/lib/namespace/clean.pm +++ b/lib/namespace/clean.pm @@ -3,13 +3,35 @@ package namespace::clean; use warnings; use strict; -use Package::Stash; - our $VERSION = '0.25'; our $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; use B::Hooks::EndOfScope 'on_scope_end'; +# FIXME This is a crock of shit, needs to go away +# currently here to work around https://rt.cpan.org/Ticket/Display.html?id=74151 +# kill with fire when PS::XS is *finally* fixed +BEGIN { + my $provider; + + if ( $] < 5.008007 ) { + require Package::Stash::PP; + $provider = 'Package::Stash::PP'; + } + else { + require Package::Stash; + $provider = 'Package::Stash'; + } + eval <<"EOS" or die $@; + +sub stash_for (\$) { + $provider->new(\$_[0]); +} + +1; + +EOS +} # Constant to optimise away the unused code branches use constant FIXUP_NEEDED => $] < 5.015_005_1; @@ -70,7 +92,7 @@ my $DebuggerFixup = sub { my $RemoveSubs = sub { my $cleanee = shift; my $store = shift; - my $cleanee_stash = Package::Stash->new($cleanee); + my $cleanee_stash = stash_for($cleanee); my $deleted_stash; SYMBOL: @@ -97,7 +119,7 @@ my $RemoveSubs = sub { $f, $sub, $cleanee_stash, - $deleted_stash ||= Package::Stash->new("namespace::clean::deleted::$cleanee"), + $deleted_stash ||= stash_for("namespace::clean::deleted::$cleanee"), ); } @@ -155,7 +177,7 @@ sub import { # calling class, all current functions and our storage my $functions = $pragma->get_functions($cleanee); my $store = $pragma->get_class_store($cleanee); - my $stash = Package::Stash->new($cleanee); + my $stash = stash_for($cleanee); # except parameter can be array ref or single value my %except = map {( $_ => 1 )} ( @@ -203,7 +225,7 @@ sub unimport { sub get_class_store { my ($pragma, $class) = @_; - my $stash = Package::Stash->new($class); + my $stash = stash_for($class); my $var = "%$STORAGE_VAR"; $stash->add_symbol($var, {}) unless $stash->has_symbol($var); @@ -213,7 +235,7 @@ sub get_class_store { sub get_functions { my ($pragma, $class) = @_; - my $stash = Package::Stash->new($class); + my $stash = stash_for($class); return { map { $_ => $stash->get_symbol("&$_") } $stash->list_all_symbols('CODE') diff --git a/t/07-debugger.t b/t/07-debugger.t index 9138a5d..598dac0 100644 --- a/t/07-debugger.t +++ b/t/07-debugger.t @@ -12,10 +12,6 @@ BEGIN { BEGIN { # shut up the debugger $ENV{PERLDB_OPTS} = 'NonStop'; - - # work aroud the regex + P::S::XS buggery on - # < 5.8.6 - require Package::Stash; } BEGIN {