Is the class $obj1 the same as $obj2 ?
ref $obj1 eq ref $obj2;
Is $obj1 class subclass of $obj2 's?
$obj1->isa(ref $obj2);
Is $obj1 a superclass of $obj2 's class?
$obj2->isa(ref $obj1);
None of the object classes is a subclass of the other.
See above.
Update:
In response to comments regarding roles used at runtime:
package My::X; use Moose; use namespace::autoclean; sub boo { } __PACKAGE__->meta->make_immutable; package My::Y; use Moose; use namespace::autoclean; extends 'My::X'; __PACKAGE__->meta->make_immutable; package My::Z; use Moose::Role; use namespace::autoclean; requires 'boo'; package main; use Test::More tests => 2; use Moose::Util qw( apply_all_roles ); my $x = My::X->new; my $y = My::Y->new; ok($y->isa(ref $x), 'Before role was applied at runtime'); apply_all_roles($x, 'My::Z'); ok($y->isa(ref $x), 'After role was applied at runtime');
Output:
1..2
ok 1 - Before role was applied at runtime
not ok 2 - After role was applied at runtime
# Failed test 'After role was applied at runtime' at C: \ Temp \ t.pl line 36.
# Looks like you failed 1 test of 2.
source share