RequireMethodModifiers policy
[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
17 my $map = $meta->get_method_map;
18
19 for my $name (keys %$map) {
20 my $method = $map->{$name};
21
22 # Modifiers are always fine.
23 next if $method->isa('Class::MOP::Method::Wrapped')
24 || $method->isa('Moose::Meta::Method::Overridden')
25 || $method->isa('Moose::Meta::Method::Augmented');
26
27 # Generated methods
28 next if $method->isa('Class::MOP::Method::Generated');
29
30 # XXX: this freaking sucks
31 next if $name eq 'meta' || $name eq 'BUILD' || $name eq 'DEMOLISH';
32
33 my $next = $meta->find_next_method_by_name($name);
34
35 # Adding new methods is always fine.
36 next if !$next;
37
38 push @violations, $self->violation("The '$name' method of class " . $meta->name . " does not use a method modifier to override its superclass implementation.", $EXPL);
39 }
40
41 return @violations;
42}
43
44no Moose;
45
461;
47
48__END__
49
50=head1 NAME
51
52Perl::Critic::Policy::DynamicMoose::RequireMethodModifiers
53
54=head1 DESCRIPTION
55
56
57=head1 WARNING
58
59B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that
60ship with Perl::Critic> use pure static analysis -- they never compile nor
61execute any of the code that they analyze. However, this policy is very
62different. It actually attempts to compile your code and then compares the
63subroutines mentioned in your code to those found in the symbol table.
64Therefore you should B<not> use this Policy on any code that you do not trust,
65or may have undesirable side-effects at compile-time (such as connecting to the
66network or mutating files).
67
68For this Policy to work, all the modules included in your code must be
69installed locally, and must compile without error.
70
71=head1 AUTHOR
72
73Shawn M Moore, C<sartak@bestpractical.com>
74
75=cut
76