Don't use get_method_map either
[gitmo/Perl-Critic-Dynamic-Moose.git] / lib / Perl / Critic / Policy / DynamicMoose / RequireMethodModifiers.pm
CommitLineData
fe411924 1package Perl::Critic::Policy::DynamicMoose::RequireMethodModifiers;
2use Moose;
3extends 'Perl::Critic::Policy::DynamicMoose';
4
5use Perl::Critic::Utils ':severities';
6use Perl::Critic::Utils::Moose 'meta_type';
7
8Readonly::Scalar my $EXPL => q{Method modifiers make it clear that you're overriding methods.};
9sub default_severity { $SEVERITY_LOW }
10
11sub violates_metaclass {
12 my $self = shift;
13 my $meta = shift;
14
15 my @violations;
16
4832e38c 17 for my $name ($meta->get_method_list) {
18 my $method = $meta->get_method($name);
fe411924 19
e842cd1d 20 # override and augment modifiers are always fine.
21 next if $method->isa('Moose::Meta::Method::Overridden')
fe411924 22 || $method->isa('Moose::Meta::Method::Augmented');
23
e842cd1d 24 # Since we can implicitly override and wrap in the same class, we
25 # need to be a little more careful here.
26 if ($method->isa('Class::MOP::Method::Wrapped')) {
27 my $orig_method = $method->get_original_method;
28 next if $method->associated_metaclass->name
29 ne $orig_method->associated_metaclass->name;
30 }
31
fe411924 32 # Generated methods
33 next if $method->isa('Class::MOP::Method::Generated');
34
35 # XXX: this freaking sucks
36 next if $name eq 'meta' || $name eq 'BUILD' || $name eq 'DEMOLISH';
37
38 my $next = $meta->find_next_method_by_name($name);
39
40 # Adding new methods is always fine.
41 next if !$next;
42
43 push @violations, $self->violation("The '$name' method of class " . $meta->name . " does not use a method modifier to override its superclass implementation.", $EXPL);
44 }
45
46 return @violations;
47}
48
49no Moose;
50
511;
52
53__END__
54
55=head1 NAME
56
57Perl::Critic::Policy::DynamicMoose::RequireMethodModifiers
58
59=head1 DESCRIPTION
60
61
62=head1 WARNING
63
64B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that
65ship with Perl::Critic> use pure static analysis -- they never compile nor
66execute any of the code that they analyze. However, this policy is very
67different. It actually attempts to compile your code and then compares the
68subroutines mentioned in your code to those found in the symbol table.
69Therefore you should B<not> use this Policy on any code that you do not trust,
70or may have undesirable side-effects at compile-time (such as connecting to the
71network or mutating files).
72
73For this Policy to work, all the modules included in your code must be
74installed locally, and must compile without error.
75
76=head1 AUTHOR
77
78Shawn M Moore, C<sartak@bestpractical.com>
79
80=cut
81