Check body, because original_package_name may be a different role
[gitmo/Perl-Critic-Dynamic-Moose.git] / lib / Perl / Critic / Policy / DynamicMoose / ClassOverridesRole.pm
index 5fa76da..3b5d040 100644 (file)
@@ -1,6 +1,6 @@
 package Perl::Critic::Policy::DynamicMoose::ClassOverridesRole;
 use Moose;
-extends 'Perl::Critic::Policy::DynamicMoose';
+extends 'Perl::Critic::DynamicMoosePolicy';
 
 use Perl::Critic::Utils ':severities';
 
@@ -20,13 +20,14 @@ sub violates_metaclass {
         my $role = $application->role;
         for my $method ($role->get_method_list) {
             next if $application->is_method_excluded($method);
+            next if $application->is_method_aliased($method);
 
             my $method_object = $class->get_method($method)
                 or next;
 
-            # no metadata, should check source role to make sure it's the
-            # same as $role
-            next if $method_object->isa('Moose::Meta::Role::Method');
+            if ($method_object->isa('Moose::Meta::Role::Method')) {
+                next if $method_object->body == $role->get_method($method)->body;
+            }
 
             my $class_name = $class->name;
             my $role_name  = $role->name;