This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: Calling Perl from within C from within Perl
[perl5.git] / t / op / universal.t
CommitLineData
44a8e56a
PP
1#!./perl
2#
3# check UNIVERSAL
4#
5
ff0cee69 6print "1..11\n";
44a8e56a
PP
7
8$a = {};
9bless $a, "Bob";
ff0cee69
PP
10print "not " unless $a->isa("Bob");
11print "ok 1\n";
44a8e56a 12
ff0cee69
PP
13package Human;
14sub eat {}
44a8e56a 15
ff0cee69
PP
16package Female;
17@ISA=qw(Human);
44a8e56a 18
ff0cee69
PP
19package Alice;
20@ISA=qw(Bob Female);
21sub drink {}
22sub new { bless {} }
44a8e56a
PP
23
24package main;
ff0cee69 25$a = new Alice;
44a8e56a 26
ff0cee69
PP
27print "not " unless $a->isa("Alice");
28print "ok 2\n";
44a8e56a 29
ff0cee69
PP
30print "not " unless $a->isa("Bob");
31print "ok 3\n";
44a8e56a 32
ff0cee69
PP
33print "not " unless $a->isa("Female");
34print "ok 4\n";
35
36print "not " unless $a->isa("Human");
37print "ok 5\n";
38
39print "not " if $a->isa("Male");
40print "ok 6\n";
41
42print "not " unless $a->can("drink");
43print "ok 7\n";
44
45print "not " unless $a->can("eat");
46print "ok 8\n";
44a8e56a 47
ff0cee69
PP
48print "not " if $a->can("sleep");
49print "ok 9\n";
44a8e56a 50
ff0cee69
PP
51print "not " unless UNIVERSAL::isa([], "ARRAY");
52print "ok 10\n";
44a8e56a 53
ff0cee69
PP
54print "not " unless UNIVERSAL::isa({}, "HASH");
55print "ok 11\n";