From: Fuji, Goro Date: Sat, 12 Nov 2011 10:04:51 +0000 (+0900) Subject: Mouse::Util::does_role() respects $thing->does() method X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=31aa6299ca20515174f1b145e5b3d4dbd9e09a08;p=gitmo%2FMouse.git Mouse::Util::does_role() respects $thing->does() method --- diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 48cc6c6..17d7efe 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -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;