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");
63 test $a->isa("Female");
65 test $a->isa("Human");
67 test ! $a->isa("Male");
69 test ! $a->isa('Programmer');
74 test ! $a->can("sleep");
75 test my $ref = $a->can("drink"); # returns a coderef
76 test $a->$ref("tea") eq "drinking tea"; # ... which works
77 test $ref = $a->can("sing");
79 test $@; # ... but not if no actual subroutine
81 test (!Cedric->isa('Programmer'));
83 test (Cedric->isa('Human'));
85 push(@Cedric::ISA,'Programmer');
87 test (Cedric->isa('Programmer'));
91 base::->import('Programmer');
94 test $a->isa('Programmer');
95 test $a->isa("Female");
97 @Cedric::ISA = qw(Bob);
99 test (!Cedric->isa('Programmer'));
102 my @refs = qw(SCALAR SCALAR LVALUE GLOB ARRAY HASH CODE);
103 my @vals = ( \$b, \3.14, \substr($b,1,1), \*b, [], {}, sub {} );
104 for ($p=0; $p < @refs; $p++) {
105 for ($q=0; $q < @vals; $q++) {
106 test UNIVERSAL::isa($vals[$p], $refs[$q]) eq ($p==$q or $p+$q==1);
110 test ! UNIVERSAL::can(23, "can");
112 test $a->can("VERSION");
115 test ! $a->can("export_tags"); # a method in Exporter
117 test (eval { $a->VERSION }) == 2.718;
119 test ! (eval { $a->VERSION(2.719) }) &&
120 $@ =~ /^Alice version 2.71(?:9|8999\d+) required--this is only version 2.718 at /;
122 test (eval { $a->VERSION(2.718) }) && ! $@;
124 my $subs = join ' ', sort grep { defined &{"UNIVERSAL::$_"} } keys %UNIVERSAL::;
125 ## The test for import here is *not* because we want to ensure that UNIVERSAL
126 ## can always import; it is an historical accident that UNIVERSAL can import.
128 test $subs eq "can import isa VERSION";
130 test $subs eq "VERSION can import isa";
133 test $a->isa("UNIVERSAL");
135 test ! UNIVERSAL::isa([], "UNIVERSAL");
137 test ! UNIVERSAL::can({}, "can");
139 test UNIVERSAL::isa(Alice => "UNIVERSAL");
141 test UNIVERSAL::can(Alice => "can") == \&UNIVERSAL::can;
143 # now use UNIVERSAL.pm and see what changes
144 eval "use UNIVERSAL";
146 test $a->isa("UNIVERSAL");
148 my $sub2 = join ' ', sort grep { defined &{"UNIVERSAL::$_"} } keys %UNIVERSAL::;
149 # XXX import being here is really a bug
151 test $sub2 eq "can import isa VERSION";
153 test $sub2 eq "VERSION can import isa";
156 eval 'sub UNIVERSAL::sleep {}';
157 test $a->can("sleep");
159 test ! UNIVERSAL::can($b, "can");
161 test ! $a->can("export_tags"); # a method in Exporter
163 test ! UNIVERSAL::isa("\xff\xff\xff\0", 'HASH');
167 use UNIVERSAL qw( isa can VERSION );
169 main::test isa "Pickup", UNIVERSAL;
170 main::test can( "Pickup", "can" ) == \&UNIVERSAL::can;
171 main::test VERSION "UNIVERSAL" ;