From: Matt S Trout Date: Sun, 11 Nov 2012 19:24:16 +0000 (+0000) Subject: preserve global non-subs during unimport X-Git-Tag: v1.000008~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2434ccb3af9a1cd80365dce96350e70686c9f3c;p=gitmo%2FMoo.git preserve global non-subs during unimport --- diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index 466f3c1..9669cbf 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -84,7 +84,14 @@ sub _unimport_coderefs { foreach my $name (keys %$exports) { if ($stash->{$name} and defined(&{$stash->{$name}})) { if ($rev{$target->can($name)}) { - delete $stash->{$name}; + my $old = delete $stash->{$name}; + my $full_name = join('::',$target,$name); + # Copy everything except the code slot back into place (e.g. $has) + foreach my $type (qw(SCALAR HASH ARRAY IO)) { + next unless defined(*{$old}{$type}); + no strict 'refs'; + *$full_name = *{$old}{$type}; + } } } }