bug fixed. test is very important things!
Tokuhiro Matsuno [Mon, 13 Apr 2009 07:35:59 +0000 (16:35 +0900)]
Klass->does_role should check the parent classes.

lib/Mouse/Meta/Class.pm
t/900_bug/002_does_role_should_search_parent.t [new file with mode: 0644]

index 9e55fa4..81fb0b0 100644 (file)
@@ -309,7 +309,7 @@ sub does_role {
 
     for my $class ($self->linearized_isa) {
         next unless $class->can('meta') and $class->meta->can('roles');
-        for my $role (@{ $self->roles }) {
+        for my $role (@{ $class->meta->roles }) {
             return 1 if $role->name eq $role_name;
         }
     }
diff --git a/t/900_bug/002_does_role_should_search_parent.t b/t/900_bug/002_does_role_should_search_parent.t
new file mode 100644 (file)
index 0000000..4dd1919
--- /dev/null
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+# Klass->does_role should check the parent classes.
+
+{
+    package R1;
+    use Mouse::Role;
+}
+
+{
+    package C1;
+    use Mouse;
+    with 'R1';
+}
+
+{
+    package C2;
+    use Mouse;
+    extends 'C1';
+}
+
+ok(C1->meta->does_role('R1'));
+ok(C2->meta->does_role('R1'));
+