Remove back-compat for old Package::Stash versions
[p5sagit/namespace-clean.git] / lib / namespace / clean.pm
index eccd295..a2665a6 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use vars qw( $STORAGE_VAR );
 use Sub::Name 0.04 qw(subname);
 use Sub::Identify 0.04 qw(sub_fullname);
-use Package::Stash 0.03;
+use Package::Stash 0.18;
 use B::Hooks::EndOfScope 0.07;
 
 $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
@@ -150,7 +150,7 @@ my $RemoveSubs = sub {
         # ignore already removed symbols
         next SYMBOL if $store->{exclude}{ $f };
 
-        next SYMBOL unless $cleanee_stash->has_package_symbol($variable);
+        next SYMBOL unless $cleanee_stash->has_symbol($variable);
 
         if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
             # convince the Perl debugger to work
@@ -158,15 +158,22 @@ my $RemoveSubs = sub {
             # since we are deleting the glob where the subroutine was originally
             # defined, that assumption no longer holds, so we need to move it
             # elsewhere and point the CV's name to the new glob.
-            my $sub = $cleanee_stash->get_package_symbol($variable);
+            my $sub = $cleanee_stash->get_symbol($variable);
             if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
                 my $new_fq = $deleted_stash->name . "::$f";
                 subname($new_fq, $sub);
-                $deleted_stash->add_package_symbol($variable, $sub);
+                $deleted_stash->add_symbol($variable, $sub);
             }
         }
 
-        $cleanee_stash->remove_package_symbol($variable);
+        my ($scalar, $array, $hash, $io) = map {
+            $cleanee_stash->get_symbol($_ . $f)
+        } '$', '@', '%', '';
+        $cleanee_stash->remove_glob($f);
+        for my $var (['$', $scalar], ['@', $array], ['%', $hash], ['', $io]) {
+            next unless defined $var->[1];
+            $cleanee_stash->add_symbol($var->[0] . $f, $var->[1]);
+        }
     }
 };
 
@@ -224,7 +231,7 @@ sub import {
         # register symbols for removal, if they have a CODE entry
         for my $f (keys %$functions) {
             next if     $except{ $f };
-            next unless $stash->has_package_symbol("&$f");
+            next unless $stash->has_symbol("&$f");
             $store->{remove}{ $f } = 1;
         }
 
@@ -278,7 +285,10 @@ information about function names included and excluded from removal.
 sub get_class_store {
     my ($pragma, $class) = @_;
     my $stash = Package::Stash->new($class);
-    return $stash->get_package_symbol("%$STORAGE_VAR");
+    my $var = "%$STORAGE_VAR";
+    $stash->add_symbol($var, {})
+        unless $stash->has_symbol($var);
+    return $stash->get_symbol($var);
 }
 
 =method get_functions
@@ -294,8 +304,8 @@ sub get_functions {
 
     my $stash = Package::Stash->new($class);
     return {
-        map { $_ => $stash->get_package_symbol("&$_") }
-            $stash->list_all_package_symbols('CODE')
+        map { $_ => $stash->get_symbol("&$_") }
+            $stash->list_all_symbols('CODE')
     };
 }