1 package Perl::Critic::Policy::DynamicMoose::ClassOverridesRole;
3 extends 'Perl::Critic::Policy::DynamicMoose';
5 use Perl::Critic::Utils ':severities';
7 Readonly::Scalar my $EXPL => q{Explicitly exclude overriden methods};
8 sub default_severity { $SEVERITY_MEDIUM }
10 # Class::MOP::Class has no roles
11 sub applies_to_metaclass { 'Moose::Meta::Class' }
13 sub violates_metaclass {
19 for my $application ($class->role_applications) {
20 my $role = $application->role;
21 for my $method ($role->get_method_list) {
22 next if $application->is_method_excluded($method);
24 my $method_object = $class->get_method($method)
27 # no metadata, should check source role to make sure it's the
29 if ($method_object->isa('Moose::Meta::Role::Method')) {
30 next if $method_object->original_package_name eq $role->name;
33 my $class_name = $class->name;
34 my $role_name = $role->name;
36 my $desc = "Class '$class_name' method '$method' implicitly overrides the same method from role '$role_name'";
37 push @violations, $self->violation($desc, $EXPL);
52 Perl::Critic::Policy::DynamicMoose::ClassOverridesRole
59 B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that
60 ship with Perl::Critic> use pure static analysis -- they never compile nor
61 execute any of the code that they analyze. However, this policy is very
62 different. It actually attempts to compile your code and then compares the
63 subroutines mentioned in your code to those found in the symbol table.
64 Therefore you should B<not> use this Policy on any code that you do not trust,
65 or may have undesirable side-effects at compile-time (such as connecting to the
66 network or mutating files).
68 For this Policy to work, all the modules included in your code must be
69 installed locally, and must compile without error.
73 Shawn M Moore, C<sartak@bestpractical.com>