use strict;
no warnings 'once';
-plan(tests => 148);
+plan(tests => 150);
@A::ISA = 'B';
@B::ISA = 'C';
{
fresh_perl_is(<<EOT,
package UNIVERSAL; sub AUTOLOAD { my \$c = shift; print "\$c \$AUTOLOAD\\n" }
+sub DESTROY {} # prevent AUTOLOAD being called on DESTROY
package Xyz;
package main; Foo->$meth->[0]();
EOT
{ bless {}, "NoSub"; }
}
+{
+ # [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");
+}
+
eval { () = 3; new {} };
like $@,
qr/^Can't call method "new" without a package or object reference/,