From: Todd Hepler Date: Wed, 14 May 2008 21:48:50 +0000 (+0000) Subject: fix for Moose::Util::does_role() to handle non-Moose metaclasses X-Git-Tag: 0_55~175 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=10a745f5fb9a24b10881b12a0d6ba998ab6334dc;p=gitmo%2FMoose.git fix for Moose::Util::does_role() to handle non-Moose metaclasses --- diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 59af6ab..9a7be5a 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -42,7 +42,7 @@ sub does_role { my $meta = find_meta($class_or_obj); return unless defined $meta; - + return unless $meta->can('does_role'); return 1 if $meta->does_role($role); return; } diff --git a/t/400_moose_util/002_moose_util_does_role.t b/t/400_moose_util/002_moose_util_does_role.t index d866b0d..c05ce94 100644 --- a/t/400_moose_util/002_moose_util_does_role.t +++ b/t/400_moose_util/002_moose_util_does_role.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 8; BEGIN { use_ok('Moose::Util', ':all'); @@ -29,6 +29,20 @@ BEGIN { use Moose; } +{ + package Quux; + + use metaclass; +} + +{ + package Foo::Foo; + + use Moose::Role; + + with 'Foo'; +} + # Classes ok(does_role('Bar', 'Foo'), '... Bar does Foo'); @@ -50,3 +64,18 @@ ok(!does_role($baz, 'Foo'), '... $baz doesnt do Foo'); ok(!does_role(undef,'Foo'), '... undef doesnt do Foo'); ok(!does_role(1,'Foo'), '... 1 doesnt do Foo'); + +# non Moose metaclass + +ok(!does_role('Quux', 'Foo'), '... Quux doesnt do Foo (does not die tho)'); + +# TODO: make the below work, maybe? + +# Self + +#ok(does_role('Foo', 'Foo'), '... Foo does do Foo'); + +# sub-Roles + +#ok(does_role('Foo::Foo', 'Foo'), '... Foo::Foo does do Foo'); +