Commit | Line | Data |
ac490c58 |
1 | package Perl::Critic::Policy::Dynamic::Moose::ProhibitPublicBuilders; |
2 | use Moose; |
3 | extends 'Perl::Critic::Policy::Dynamic::Moose'; |
4 | |
5 | Readonly::Scalar my $DESC = q{Builder method name without a leading underscore}; |
6 | Readonly::Scalar my $EXPL = q{Prefix builder method names with an underscore}; |
7 | |
8 | sub violates_metaclass { |
9 | my $self = shift; |
10 | my $meta = shift; |
11 | |
12 | my @violations; |
13 | |
14 | my $attributes = $meta->get_attribute_map; |
15 | for my $name (keys %$attributes) { |
16 | my $attribute = $attributes->{$name}; |
17 | |
18 | next if !$attribute->has_builder; |
19 | |
20 | if ($attribute->builder =~ /^_/) { |
21 | push @violations, $self->violation($DESC, $EXPL); |
22 | } |
23 | } |
24 | |
25 | return @violations; |
26 | } |
27 | |
28 | __PACKAGE__->meta->make_immutable; |
29 | no Moose; |
30 | |
31 | 1; |
32 | |