Skip Menu |

This queue is for tickets about the aliased CPAN distribution.

Report information
The Basics
Id: 83977
Status: rejected
Priority: 0/
Queue: aliased

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.31
Fixed in: (no value)



Subject: isa() does not understand aliases
use strict; use warnings; use aliased 'Test::More' => 'Foo'; isa_ok('Test::More', 'Test::More'); isa_ok('Foo', 'Test::More'); isa_ok('Test::More', 'Foo'); my $obj = bless {}, 'Test::More'; isa_ok($obj, 'Test::More'); isa_ok($obj, 'Foo'); done_testing; prints: ok 1 - The class isa Test::More not ok 2 - The class isa Test::More # Failed test 'The class isa Test::More' # at aliased.pl line 7. # The class isn't a 'Test::More' it's a '' not ok 3 - The class isa Foo # Failed test 'The class isa Foo' # at aliased.pl line 8. # The class isn't a 'Foo' it's a '' ok 4 - The object isa Test::More not ok 5 - The object isa Foo # Failed test 'The object isa Foo' # at aliased.pl line 12. # The object isn't a 'Foo' it's a 'Test::More' 1..5 # Looks like you failed 3 tests of 5.
On Fri Mar 15 14:58:57 2013, ETHER wrote: Show quoted text
> use strict; > use warnings; > > use aliased 'Test::More' => 'Foo'; > > isa_ok('Test::More', 'Test::More'); > isa_ok('Foo', 'Test::More'); > isa_ok('Test::More', 'Foo'); > > my $obj = bless {}, 'Test::More'; > isa_ok($obj, 'Test::More'); > isa_ok($obj, 'Foo'); > > done_testing; > > prints: > > ok 1 - The class isa Test::More > not ok 2 - The class isa Test::More > # Failed test 'The class isa Test::More' > # at aliased.pl line 7. > # The class isn't a 'Test::More' it's a '' > not ok 3 - The class isa Foo > # Failed test 'The class isa Foo' > # at aliased.pl line 8. > # The class isn't a 'Foo' it's a '' > ok 4 - The object isa Test::More > not ok 5 - The object isa Foo > # Failed test 'The object isa Foo' > # at aliased.pl line 12. > # The object isn't a 'Foo' it's a 'Test::More' > 1..5 > # Looks like you failed 3 tests of 5. >
Hi Karen, This actually is not a bug. Foo, in your example, is not a string, nor is it a classname. When you do this: use aliased 'Test::More' => 'Foo'; That's equivalent to this: use Test::More; sub Foo() { return 'Test::More' } Due to the null prototype, this becomes a constant subroutine and its return value is inlined into the code. The following should make this clear: % perl -Maliased=Test::More,Foo -MO=Deparse -e "print Foo; print 'Foo'" print 'Test::More'; print 'Foo'; -e syntax OK So to fix your test, just do this: use strict; use warnings; use aliased 'Test::More' => 'Foo'; isa_ok('Test::More', 'Test::More'); isa_ok(Foo, 'Test::More'); isa_ok('Test::More', Foo); my $obj = bless {}, 'Test::More'; isa_ok($obj, 'Test::More'); isa_ok($obj, Foo); done_testing; Cheers, Ovid PS: I've made this same mistake and I wrote the module! Makes me feel kind of silly sometimes when I do that :)