scope.c:save_gp: Remove redundant code

This has been redundant since ERRSV was changed to use GvSVn in com-
mit f5fa9033b8.
Fix two minor bugs with local glob assignment

These are combined into one patch because it is hard to fix one with-
out fixing the other.

local *glob = $ref was ignoring the clobbered reference and not
accounting for when updating ISA caches, resulting in two bugs:

*Foo::ISA = *Bar::ISA;
@Foo::ISA = "Baz";
sub Baz::ook { "Baz" }
sub L::ook { "See" }
warn Bar->ook;         # Baz
local *Foo::ISA = ["L"];
warn Bar->ook;         # Baz
@Baz::ISA = @Baz::ISA; # should have no effect
warn Bar->ook;         # See

@Baz::ISA = "Foo::bar";
sub Foo::bar::ber { 'baz' }
sub UNIVERSAL::ber { "black sheep" }
warn Baz->ber;         # baz
local *Foo:: = \%Bar::;
warn Baz->ber;         # baz
@Baz::ISA = @Baz::ISA; # should have no effect
warn Baz->ber;         # black sheep

The dref variable in sv.c:S_glob_assign_ref holds the SV that needs to
be freed.  So during localisation it is NULL.

When I was fixing up isa and mro bugs in perl 5.14, I misunderstood
its purpose and thought it always contained the reference on the left.

Since we need to have access to what was assigned over after the
assignment, this commit changes dref always to hold the clobbered SV,
and makes the SvREFCNT_dec conditional.
Reset method caches when GPs are shared

The new MRO stuff in 5.10 made PL_sub_generation++ mostly unnecessary,
and almost all uses of it were replaced with mro_method_changed_in.

There is only one problem: That doesn’t actually work properly.  After
glob-to-glob assignment (*foo = *bar), both globs share the same GP
(glob pointer, or list of glob slots).  But there is no list of GVs
associated with any GP.  So there is no way, given a GV whose GP
is shared, to find out what other classes might need their method
caches reset.

sub B::b { "b" }
*A::b = *B::b;
@C::ISA = "A";
print C->b, "\n";  # should print "b"
eval 'sub B::b { "c" }';
print C->b, "\n";  # should print "c"
__END__

$ perl5.8.9 foo
b
c
$ perl5.10.0 foo
b
b

And it continues up to 5.16.x.

If a GP is shared, then those places where mro_method_changed_in is
called after the GP has been modified must do PL_sub_generation++
instead if the GP is shared, which can be detected through its refer-
ence count.
Don’t croak for local *DetachedStash::method

save_gp was trying to call mro_method_changed_in even if the stash had
been detached.

This is a regression from 5.12.
Fix two local *ISA bugs

These are regressions from 5.8.

local *ISA was not updating isa caches. local *ISA = [] was updating
caches, but scope unwinding was not.

Both save_gp and leave_scope/SAVEt_GP need to check whether the glob
is named ISA and call mro_isa_changed_in if appropriate.
Clear method caches when unwinding local *foo=*method

It was already working for those cases where *foo contained a sub
before and after localisation.  For those cases where *foo had no sub
but localised assignment gave it one, method caches were not being
reset on scope exit.

case SAVEt_GP in scope.c:leave_scope needs to look at both GPs (glob
pointer, or list of glob slots), both from before and after the unlo-
calisation.  If either has a sub, method caches need to be cleared.

This does not yet fix local *foo = sub {}, but I added a to-do
test for it.  (This is more complicated, as localisation happens in
two seperate steps, the glob slot localisation storing no pointers to
the glob itself on the savestack.)
method_caching.t: Load test.pl at BEGIN time

This stops $::TODO from producing a used-only-once warning.
Clear method caches when unwinding local *foo=sub{}

local *foo=sub{} is done in two stages:

• First the local *foo localises the GP (the glob pointer, or list of
  slots), setting a flag on the GV.
• Then scalar assignment sees the flag on the GV on the LHS and loca-
  lises a single slot.

The slot localisation only stores on the savestack a pointer into the
GP struct and the old value.  There is no reference to the GV.

To restore a method properly, we have to have a reference to the GV
when the slot localisation is undone.

So in this commit I have added a new save type, SAVEt_GVSLOT.  It is
like SAVEt_GENERIC_SV, except it pushes the GV as well.  Currently
it is used only for CVs, but I will need it for HVs and maybe
AVs as well.

It is possible for the unwinding of the slot localisation to affect
only a GV other than the one that is pushed, if glob assignments have
taken place since the local *foo.  So we have to check whether the
pointer is inside the GP and use PL_sub_generation++ if it is not.