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 {}';
122 use UNIVERSAL qw( isa can VERSION );
124 ::ok isa "Pìckùp", UNIVERSAL;
125 ::cmp_ok can( "Pìckùp", "can" ), '==', \&UNIVERSAL::can;
126 ::ok VERSION "UNIVERSAL" ;
140 ok( Fòò->DOES( 'bàr' ), 'DOES() should call DOES() on class' );
141 ok( Bàr->DOES( 'Bàr' ), '... and should fall back to isa()' );
142 ok( Bàr->DOES( 'Fòò' ), '... even when inherited' );
143 ok( Bàz->DOES( 'Bàz' ), '... even without inheriting any other DOES()' );
144 ok( ! Bàz->DOES( 'Fòò' ), '... returning true or false appropriately' );
151 eval { UNIVERSAL::DOES([], "fòò") };
152 like( $@, qr/Can't call method "DOES" on unblessed reference/,
153 'DOES call error message says DOES, not isa' );
155 # Tests for can seem to be split between here and method.t
156 # Add the verbatim perl code mentioned in the comments of
157 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-05/msg01710.html
158 # but never actually tested.
159 is(UNIVERSAL->can("NòSùchPàckàgè::fòò"), undef);
161 @splàtt::ISA = 'zlòpp';
162 ok (splàtt->isa('zlòpp'));
163 ok (!splàtt->isa('plòp'));
165 # This should reset the ->isa lookup cache
166 @splàtt::ISA = 'plòp';
167 # And here is the new truth.
168 ok (!splàtt->isa('zlòpp'));
169 ok (splàtt->isa('plòp'));