Make does_role accept a role meta object
gfx [Fri, 26 Feb 2010 09:24:11 +0000 (18:24 +0900)]
lib/Mouse/Meta/Class.pm
lib/Mouse/Meta/Role.pm

index 7a9dd8b..276b16d 100644 (file)
@@ -96,7 +96,7 @@ sub _reconcile_with_superclass_meta {
 
     my @roles;
     foreach my $role($super_meta->meta->calculate_all_roles){
-        if(!$self->meta->does_role($role->name)){
+        if(!$self->meta->does_role($role)){
             push @roles, $role->name;
         }
     }
@@ -439,6 +439,8 @@ sub does_role {
     (defined $role_name)
         || $self->throw_error("You must supply a role name to look for");
 
+    $role_name = $role_name->name if ref $role_name;
+
     for my $class ($self->linearized_isa) {
         my $meta = Mouse::Util::get_metaclass_by_name($class)
             or next;
index a41d5a6..c030b70 100644 (file)
@@ -170,7 +170,7 @@ sub _append_roles{
     my $roles = $consumer->{roles};
 
     foreach my $r($role, @{$role->get_roles}){
-        if(!$consumer->does_role($r->name)){
+        if(!$consumer->does_role($r)){
             push @{$roles}, $r;
         }
     }
@@ -288,6 +288,8 @@ sub does_role {
     (defined $role_name)
         || $self->throw_error("You must supply a role name to look for");
 
+    $role_name = $role_name->name if ref $role_name;
+
     # if we are it,.. then return true
     return 1 if $role_name eq $self->name;
     # otherwise.. check our children