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