+{
+ # [perl #124387]
+ my $autoloaded;
+ package AutoloadDestroy;
+ sub AUTOLOAD { $autoloaded = 1 }
+ package main;
+ bless {}, "AutoloadDestroy";
+ ok($autoloaded, "AUTOLOAD called for DESTROY");
+
+ # 127494 - AUTOLOAD for DESTROY was called without setting $AUTOLOAD
+ my %methods;
+ package AutoloadDestroy2;
+ sub AUTOLOAD {
+ our $AUTOLOAD;
+ (my $method = $AUTOLOAD) =~ s/.*:://;
+ ++$methods{$method};
+ }
+ package main;
+ # this cached AUTOLOAD as the DESTROY method
+ bless {}, "AutoloadDestroy2";
+ %methods = ();
+ my $o = bless {}, "AutoloadDestroy2";
+ # this sets $AUTOLOAD to "AutoloadDestroy2::foo"
+ $o->foo;
+ # this would call AUTOLOAD without setting $AUTOLOAD
+ undef $o;
+ ok($methods{DESTROY}, "\$AUTOLOAD set correctly for DESTROY");
+}
+