Commit | Line | Data |
042287b0 |
1 | package Perl::Critic::Policy::DynamicMoose::ClassOverridesRole; |
2 | use Moose; |
3 | extends 'Perl::Critic::Policy::DynamicMoose'; |
4 | |
5 | use Perl::Critic::Utils ':severities'; |
6 | |
34b35078 |
7 | Readonly::Scalar my $EXPL => q{Explicitly exclude overriden methods}; |
042287b0 |
8 | sub default_severity { $SEVERITY_MEDIUM } |
9 | |
425e287e |
10 | # Class::MOP::Class has no roles |
11 | sub applies_to_metaclass { 'Moose::Meta::Class' } |
12 | |
042287b0 |
13 | sub violates_metaclass { |
34b35078 |
14 | my $self = shift; |
15 | my $class = shift; |
042287b0 |
16 | |
34b35078 |
17 | my @violations; |
18 | |
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); |
aa65a014 |
23 | next if $application->is_method_aliased($method); |
34b35078 |
24 | |
25 | my $method_object = $class->get_method($method) |
26 | or next; |
27 | |
28 | # no metadata, should check source role to make sure it's the |
29 | # same as $role |
c3c1ebd6 |
30 | if ($method_object->isa('Moose::Meta::Role::Method')) { |
31 | next if $method_object->original_package_name eq $role->name; |
32 | } |
34b35078 |
33 | |
34 | my $class_name = $class->name; |
35 | my $role_name = $role->name; |
36 | |
37 | my $desc = "Class '$class_name' method '$method' implicitly overrides the same method from role '$role_name'"; |
38 | push @violations, $self->violation($desc, $EXPL); |
39 | } |
40 | } |
41 | |
42 | return @violations; |
042287b0 |
43 | } |
44 | |
45 | no Moose; |
46 | |
47 | 1; |
48 | |
49 | __END__ |
50 | |
51 | =head1 NAME |
52 | |
53 | Perl::Critic::Policy::DynamicMoose::ClassOverridesRole |
54 | |
55 | =head1 DESCRIPTION |
56 | |
57 | |
58 | =head1 WARNING |
59 | |
60 | B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that |
61 | ship with Perl::Critic> use pure static analysis -- they never compile nor |
62 | execute any of the code that they analyze. However, this policy is very |
63 | different. It actually attempts to compile your code and then compares the |
64 | subroutines mentioned in your code to those found in the symbol table. |
65 | Therefore you should B<not> use this Policy on any code that you do not trust, |
66 | or may have undesirable side-effects at compile-time (such as connecting to the |
67 | network or mutating files). |
68 | |
69 | For this Policy to work, all the modules included in your code must be |
70 | installed locally, and must compile without error. |
71 | |
72 | =head1 AUTHOR |
73 | |
74 | Shawn M Moore, C<sartak@bestpractical.com> |
75 | |
76 | =cut |
77 | |