16 print "not " unless $a->isa("Bob");
28 sub drink { return "drinking " . $_[1] }
31 $Alice::VERSION = 2.718;
50 print "not " unless $_[0];
52 print " # at ", (caller)[1], ", line ", (caller)[2] unless $_[0];
59 test $a->isa("Alice");
60 test $a->isa("main::Alice"); # check that alternate class names work
63 test $a->isa("main::Bob");
65 test $a->isa("Female");
67 test $a->isa("Human");
69 test ! $a->isa("Male");
71 test ! $a->isa('Programmer');
76 test ! $a->can("sleep");
77 test my $ref = $a->can("drink"); # returns a coderef
78 test $a->$ref("tea") eq "drinking tea"; # ... which works
79 test $ref = $a->can("sing");
81 test $@; # ... but not if no actual subroutine
83 test (!Cedric->isa('Programmer'));
85 test (Cedric->isa('Human'));
87 push(@Cedric::ISA,'Programmer');
89 test (Cedric->isa('Programmer'));
93 base::->import('Programmer');
96 test $a->isa('Programmer');
97 test $a->isa("Female");
99 @Cedric::ISA = qw(Bob);
101 test (!Cedric->isa('Programmer'));
104 my @refs = qw(SCALAR SCALAR LVALUE GLOB ARRAY HASH CODE);
105 my @vals = ( \$b, \3.14, \substr($b,1,1), \*b, [], {}, sub {} );
106 for ($p=0; $p < @refs; $p++) {
107 for ($q=0; $q < @vals; $q++) {
108 test UNIVERSAL::isa($vals[$p], $refs[$q]) eq ($p==$q or $p+$q==1);
112 test ! UNIVERSAL::can(23, "can");
114 test $a->can("VERSION");
117 test ! $a->can("export_tags"); # a method in Exporter
119 test (eval { $a->VERSION }) == 2.718;
121 test ! (eval { $a->VERSION(2.719) }) &&
122 $@ =~ /^Alice version 2.71(?:9|8999\d+) required--this is only version 2.718 at /;
124 test (eval { $a->VERSION(2.718) }) && ! $@;
126 my $subs = join ' ', sort grep { defined &{"UNIVERSAL::$_"} } keys %UNIVERSAL::;
127 ## The test for import here is *not* because we want to ensure that UNIVERSAL
128 ## can always import; it is an historical accident that UNIVERSAL can import.
130 test $subs eq "can import isa VERSION";
132 test $subs eq "VERSION can import isa";
135 test $a->isa("UNIVERSAL");
137 test ! UNIVERSAL::isa([], "UNIVERSAL");
139 test ! UNIVERSAL::can({}, "can");
141 test UNIVERSAL::isa(Alice => "UNIVERSAL");
143 test UNIVERSAL::can(Alice => "can") == \&UNIVERSAL::can;
145 # now use UNIVERSAL.pm and see what changes
146 eval "use UNIVERSAL";
148 test $a->isa("UNIVERSAL");
150 my $sub2 = join ' ', sort grep { defined &{"UNIVERSAL::$_"} } keys %UNIVERSAL::;
151 # XXX import being here is really a bug
153 test $sub2 eq "can import isa VERSION";
155 test $sub2 eq "VERSION can import isa";
158 eval 'sub UNIVERSAL::sleep {}';
159 test $a->can("sleep");
161 test ! UNIVERSAL::can($b, "can");
163 test ! $a->can("export_tags"); # a method in Exporter
165 test ! UNIVERSAL::isa("\xff\xff\xff\0", 'HASH');
169 use UNIVERSAL qw( isa can VERSION );
171 main::test isa "Pickup", UNIVERSAL;
172 main::test can( "Pickup", "can" ) == \&UNIVERSAL::can;
173 main::test VERSION "UNIVERSAL" ;