1 package Perl::Critic::Policy::DynamicMoose::RequireMethodModifiers;
3 extends 'Perl::Critic::Policy::DynamicMoose';
5 use Perl::Critic::Utils ':severities';
6 use Perl::Critic::Utils::Moose 'meta_type';
8 Readonly::Scalar my $EXPL => q{Method modifiers make it clear that you're overriding methods.};
9 sub default_severity { $SEVERITY_LOW }
11 sub violates_metaclass {
17 for my $name ($class->get_method_list) {
18 my $method = $class->get_method($name);
20 # override and augment modifiers are always fine.
21 next if $method->isa('Moose::Meta::Method::Overridden')
22 || $method->isa('Moose::Meta::Method::Augmented');
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;
33 next if $method->isa('Class::MOP::Method::Generated');
35 # XXX: this freaking sucks
36 next if $name eq 'meta' || $name eq 'BUILD' || $name eq 'DEMOLISH';
38 my $next = $class->find_next_method_by_name($name);
40 # Adding new methods is always fine.
43 push @violations, $self->violation("The '$name' method of class " . $class->name . " does not use a method modifier to override its superclass implementation.", $EXPL);
57 Perl::Critic::Policy::DynamicMoose::RequireMethodModifiers
64 B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that
65 ship with Perl::Critic> use pure static analysis -- they never compile nor
66 execute any of the code that they analyze. However, this policy is very
67 different. It actually attempts to compile your code and then compares the
68 subroutines mentioned in your code to those found in the symbol table.
69 Therefore you should B<not> use this Policy on any code that you do not trust,
70 or may have undesirable side-effects at compile-time (such as connecting to the
71 network or mutating files).
73 For this Policy to work, all the modules included in your code must be
74 installed locally, and must compile without error.
78 Shawn M Moore, C<sartak@bestpractical.com>