Commit | Line | Data |
ac490c58 |
1 | package Perl::Critic::Policy::Dynamic::Moose::ProhibitPublicBuilders; |
2 | use Moose; |
3 | extends 'Perl::Critic::Policy::Dynamic::Moose'; |
4 | |
9e6b568b |
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}; |
ac490c58 |
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 | |
ac490c58 |
28 | no Moose; |
29 | |
30 | 1; |
31 | |