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