Saving Perl packages through local

In Perl there is an expression local. It substitutes the specified value with undef until the end of the block. The values can be global hashes, arrays and scalars, as well as elements or slices of hashes and scalars. The problem is that package hashes are not saved by local. By package hashes I mean a hash with a colon at the end (%Package::) which stores the package symbols (GLOB).

package A {
  sub fn {}
  $x = 10;
  @x = qw(1 2);
}

use DDP;
p %A::  # -> {
        #    fn   *A::fn  (layers: ),
        #    x    *A::x  (layers: )
        # }
Here @x and $x are in the same globe - *A::x. They can be accessed as follows:

package A {
	sub fn {}
	$x = 10;
	@x = qw(1 2);
}

$\ = "\n"; $, = ", ";

print $A::x, ${ *A::x{SCALAR} }, ${ *{ $A::{x} }{SCALAR} }; 
# -> 10, 10, 10
print @A::x, @{ *A::x{ARRAY} }, @{ *{ $A::{x} }{ARRAY} }; 
# -> 1, 2, 1, 2, 1, 2

About Den

user-pic Old dev