4 # test method calls and autoloading.
17 print "# got `$_[0]', expected `$_[1]'\nnot " unless $_[0] eq $_[1];
18 # print "not " unless shift eq shift;
19 print "ok ", ++$cnt, "\n"
22 test( A->d, "C::d"); # Update hash table;
24 *B::d = \&D::d; # Import now.
25 test (A->d, "D::d"); # Update hash table;
28 local @A::ISA = qw(C); # Update hash table with split() assignment
31 test (eval { A->d } || "fail", "fail");
37 eval 'sub B::d {"B::d1"}'; # Import now.
38 test (A->d, "B::d1"); # Update hash table;
40 test ((eval { A->d }, ($@ =~ /Undefined subroutine/)), 1);
43 test (A->d, "D::d"); # Back to previous state
45 eval 'sub B::d {"B::d2"}'; # Import now.
46 test (A->d, "B::d2"); # Update hash table;
48 # What follows is hardly guarantied to work, since the names in scripts
49 # are already linked to "pruned" globs. Say, `undef &B::d' if it were
50 # after `delete $B::{d}; sub B::d {}' would reach an old subroutine.
54 test (A->d, "C::d"); # Update hash table;
56 eval 'sub B::d {"B::d3"}'; # Import now.
57 test (A->d, "B::d3"); # Update hash table;
60 *dummy::dummy = sub {}; # Mark as updated
63 eval 'sub B::d {"B::d4"}'; # Import now.
64 test (A->d, "B::d4"); # Update hash table;
66 delete $B::{d}; # Should work without any help too
69 *A::x = *A::d; # See if cache incorrectly follows synonyms
71 test (eval { A->x } || "nope", "nope");
75 BEGIN { *B::e = \&C::e } # Shouldn't prevent AUTOLOAD in original pkg
84 my $method = $B::AUTOLOAD;
85 my $msg = "B: In $method, $c";
86 eval "sub $method { \$msg }";
91 my $method = $C::AUTOLOAD;
92 my $msg = "C: In $method, $c";
93 eval "sub $method { \$msg }";
98 test(A->e(), "C: In C::e, 1"); # We get a correct autoload
99 test(A->e(), "C: In C::e, 1"); # Which sticks
101 test(A->ee(), "B: In A::ee, 2"); # We get a generic autoload, method in top
102 test(A->ee(), "B: In A::ee, 2"); # Which sticks
104 test(Y->f(), "B: In Y::f, 3"); # We vivify a correct method
105 test(Y->f(), "B: In Y::f, 3"); # Which sticks
107 # This test is not intended to be reasonable. It is here just to let you
108 # know that you broke some old construction. Feel free to rewrite the test
109 # if your patch breaks it.
113 my $method = $AUTOLOAD;
114 *$AUTOLOAD = sub { "new B: In $method, $c" };
118 test(A->eee(), "new B: In A::eee, 4"); # We get a correct $autoload
119 test(A->eee(), "new B: In A::eee, 4"); # Which sticks
121 # this test added due to bug discovery
122 test(defined(@{"unknown_package::ISA"}) ? "defined" : "undefined", "undefined");