summaryrefslogtreecommitdiff
path: root/t/op/universal.t
blob: 03f0fbdd9da85bdce25375e039f502402fe86a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!./perl
#
# check UNIVERSAL
#

print "1..11\n";

$a = {};
bless $a, "Bob";
print "not " unless $a->isa("Bob");
print "ok 1\n";

package Human;
sub eat {}

package Female;
@ISA=qw(Human);

package Alice;
@ISA=qw(Bob Female);
sub drink {}
sub new { bless {} }

package main;
$a = new Alice;

print "not " unless $a->isa("Alice");
print "ok 2\n";

print "not " unless $a->isa("Bob");
print "ok 3\n";

print "not " unless $a->isa("Female");
print "ok 4\n";

print "not " unless $a->isa("Human");
print "ok 5\n";

print "not " if $a->isa("Male");
print "ok 6\n";

print "not " unless $a->can("drink");
print "ok 7\n";

print "not " unless $a->can("eat");
print "ok 8\n";

print "not " if $a->can("sleep");
print "ok 9\n";

print "not " unless UNIVERSAL::isa([], "ARRAY");
print "ok 10\n";

print "not " unless UNIVERSAL::isa({}, "HASH");
print "ok 11\n";