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