10 set_up_inc(qw '../lib ../dist/base/lib');
14 use open qw( :utf8 :std );
31 sub drìnk { return "drinking " . $_[1] }
34 $Àlìcè::VERSION = 2.718;
54 ok $a->isa("main::Àlìcè"); # check that alternate class names work
55 ok(("main::Àlìcè"->nèw)->isa("Àlìcè"));
58 ok $a->isa("main::Bòb");
66 ok ! $a->isa('Prògràmmèr');
71 ok ! $a->can("sleep");
72 ok my $ref = $a->can("drìnk"); # returns a coderef
73 is $a->$ref("tèà"), "drinking tèà"; # ... which works
74 ok $ref = $a->can("sìng");
76 ok $@; # ... but not if no actual subroutine
78 ok $a->can("VERSION");
79 cmp_ok eval { $a->VERSION }, '==', 2.718;
80 ok ! (eval { $a->VERSION(2.719) });
81 like $@, qr/^Àlìcè version 2.719 required--this is only version 2.718 at /u;
83 ok (!Cèdrìc->isa('Prògràmmèr'));
85 ok (Cèdrìc->isa('Hùmàn'));
87 push(@Cèdrìc::ISA,'Prògràmmèr');
89 ok (Cèdrìc->isa('Prògràmmèr'));
93 base::->import('Prògràmmèr');
96 ok $a->isa('Prògràmmèr');
99 @Cèdrìc::ISA = qw(Bòb);
101 ok (!Cèdrìc->isa('Prògràmmèr'));
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 is UNIVERSAL::isa($vals[$p], $refs[$q]), ($p==$q or $p+$q==1);
113 ok UNIVERSAL::isa(Àlìcè => "UNIVERSAL");
115 cmp_ok UNIVERSAL::can(Àlìcè => "can"), '==', \&UNIVERSAL::can;
117 eval 'sub UNIVERSAL::slèèp {}';
131 ok( Fòò->DOES( 'bàr' ), 'DOES() should call DOES() on class' );
132 ok( Bàr->DOES( 'Bàr' ), '... and should fall back to isa()' );
133 ok( Bàr->DOES( 'Fòò' ), '... even when inherited' );
134 ok( Bàz->DOES( 'Bàz' ), '... even without inheriting any other DOES()' );
135 ok( ! Bàz->DOES( 'Fòò' ), '... returning true or false appropriately' );
142 eval { UNIVERSAL::DOES([], "fòò") };
143 like( $@, qr/Can't call method "DOES" on unblessed reference/,
144 'DOES call error message says DOES, not isa' );
146 # Tests for can seem to be split between here and method.t
147 # Add the verbatim perl code mentioned in the comments of
148 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-05/msg01710.html
149 # but never actually tested.
150 is(UNIVERSAL->can("NòSùchPàckàgè::fòò"), undef);
152 @splàtt::ISA = 'zlòpp';
153 ok (splàtt->isa('zlòpp'));
154 ok (!splàtt->isa('plòp'));
156 # This should reset the ->isa lookup cache
157 @splàtt::ISA = 'plòp';
158 # And here is the new truth.
159 ok (!splàtt->isa('zlòpp'));
160 ok (splàtt->isa('plòp'));