Mouse::Util::does_role() respects $thing->does() method master
Fuji, Goro [Sat, 12 Nov 2011 10:04:51 +0000 (19:04 +0900)]
lib/Mouse/Util.pm

index 48cc6c6..17d7efe 100644 (file)
@@ -169,7 +169,7 @@ sub find_meta{
     return class_of( $_[0] );
 }
 
-sub does_role{
+sub _does_role_impl {
     my ($class_or_obj, $role_name) = @_;
 
     my $meta = class_of($class_or_obj);
@@ -180,6 +180,16 @@ sub does_role{
     return defined($meta) && $meta->does_role($role_name);
 }
 
+sub does_role {
+    my($thing, $role_name) = @_;
+
+    if( (Scalar::Util::blessed($thing) || is_class_loaded($thing))
+            && $thing->can('does')) {
+        return $thing->does($role_name);
+    }
+    goto &_does_role_impl;
+}
+
 # taken from Mouse::Util (0.90)
 {
     my %cache;
@@ -377,7 +387,7 @@ sub dump :method {
 
 # general does() method
 sub does :method {
-    goto &does_role;
+    goto &_does_role_impl;
 }
 
 1;