11 use open qw( :utf8 :std );
20 ::like $@, qr/Undefined subroutine &main::ok called at/u;
24 sub { @c = caller(0) } -> ();
25 ::is( $c[3], "main::__ANON__", "anonymous subroutine name" );
26 ::ok( $c[4], "hasargs true with anon sub" );
28 # Bug 20020517.003 (#9367), used to dump core
29 sub foo { @c = caller(0) }
30 # The subroutine only gets anonymised if it is relying on a real GV
32 () = *{"foo"}; # with quotes so that the op tree doesn’t reference the GV
33 my $fooref = delete $main::{foo};
35 ::is( $c[3], "main::__ANON__", "deleted subroutine name" );
36 ::ok( $c[4], "hasargs true with deleted sub" );
38 print "# Tests with caller(1)\n";
40 sub f { @c = caller(1) }
44 ::is( $c[3], "main::callf", "subroutine name" );
45 ::ok( $c[4], "hasargs true with callf()" );
47 ::ok( !$c[4], "hasargs false with &callf" );
50 ::is( $c[3], "(eval)", "subroutine name in an eval {}" );
51 ::ok( !$c[4], "hasargs false in an eval {}" );
54 ::is( $c[3], "(eval)", "subroutine name in an eval ''" );
55 ::ok( !$c[4], "hasargs false in an eval ''" );
58 ::is( $c[3], "main::__ANON__", "anonymous subroutine name" );
59 ::ok( $c[4], "hasargs true with anon sub" );
62 () = *{"foo2"}; # see foo notes above
63 my $fooref2 = delete $main::{foo2};
65 ::is( $c[3], "main::__ANON__", "deleted subroutine name" );
66 ::ok( $c[4], "hasargs true with deleted sub" );
68 sub pb { return (caller(0))[3] }
70 ::is( eval 'pb()', 'main::pb', "actually return the right function name" );
72 my $saved_perldb = $^P;
76 ::is( eval 'pb()', 'main::pb', 'actually return the right function name even if $^P had been on at some point' );