source: trunk/essentials/dev-lang/perl/t/op/method.t@ 3298

Last change on this file since 3298 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 8.2 KB
Line 
1#!./perl
2
3#
4# test method calls and autoloading.
5#
6
7BEGIN {
8 chdir 't' if -d 't';
9 @INC = qw(. ../lib);
10 require "test.pl";
11}
12
13print "1..78\n";
14
15@A::ISA = 'B';
16@B::ISA = 'C';
17
18sub C::d {"C::d"}
19sub D::d {"D::d"}
20
21# First, some basic checks of method-calling syntax:
22$obj = bless [], "Pack";
23sub Pack::method { shift; join(",", "method", @_) }
24$mname = "method";
25
26is(Pack->method("a","b","c"), "method,a,b,c");
27is(Pack->$mname("a","b","c"), "method,a,b,c");
28is(method Pack ("a","b","c"), "method,a,b,c");
29is((method Pack "a","b","c"), "method,a,b,c");
30
31is(Pack->method(), "method");
32is(Pack->$mname(), "method");
33is(method Pack (), "method");
34is(Pack->method, "method");
35is(Pack->$mname, "method");
36is(method Pack, "method");
37
38is($obj->method("a","b","c"), "method,a,b,c");
39is($obj->$mname("a","b","c"), "method,a,b,c");
40is((method $obj ("a","b","c")), "method,a,b,c");
41is((method $obj "a","b","c"), "method,a,b,c");
42
43is($obj->method(0), "method,0");
44is($obj->method(1), "method,1");
45
46is($obj->method(), "method");
47is($obj->$mname(), "method");
48is((method $obj ()), "method");
49is($obj->method, "method");
50is($obj->$mname, "method");
51is(method $obj, "method");
52
53is( A->d, "C::d"); # Update hash table;
54
55*B::d = \&D::d; # Import now.
56is(A->d, "D::d"); # Update hash table;
57
58{
59 local @A::ISA = qw(C); # Update hash table with split() assignment
60 is(A->d, "C::d");
61 $#A::ISA = -1;
62 is(eval { A->d } || "fail", "fail");
63}
64is(A->d, "D::d");
65
66{
67 local *B::d;
68 eval 'sub B::d {"B::d1"}'; # Import now.
69 is(A->d, "B::d1"); # Update hash table;
70 undef &B::d;
71 is((eval { A->d }, ($@ =~ /Undefined subroutine/)), 1);
72}
73
74is(A->d, "D::d"); # Back to previous state
75
76eval 'sub B::d {"B::d2"}'; # Import now.