From: Shawn M Moore Date: Tue, 28 Apr 2009 08:27:45 +0000 (-0400) Subject: Handle roles in ProhibitPublicBuilders X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=914f300c017509173ef3d6b5e553e69ff7e52740;p=gitmo%2FPerl-Critic-Dynamic-Moose.git Handle roles in ProhibitPublicBuilders --- diff --git a/lib/Perl/Critic/Policy/DynamicMoose.pm b/lib/Perl/Critic/Policy/DynamicMoose.pm index c0c9036..e4f66fb 100644 --- a/lib/Perl/Critic/Policy/DynamicMoose.pm +++ b/lib/Perl/Critic/Policy/DynamicMoose.pm @@ -10,7 +10,7 @@ has document => ( ); sub applies_to { 'PPI::Document' } -sub applies_to_metaclass { 'Class::MOP::Class' } +sub applies_to_metaclass { 'Class::MOP::Class', inner() } around violation => sub { my $orig = shift; diff --git a/lib/Perl/Critic/Policy/DynamicMoose/ProhibitPublicBuilders.pm b/lib/Perl/Critic/Policy/DynamicMoose/ProhibitPublicBuilders.pm index 03bb8f6..90155ab 100644 --- a/lib/Perl/Critic/Policy/DynamicMoose/ProhibitPublicBuilders.pm +++ b/lib/Perl/Critic/Policy/DynamicMoose/ProhibitPublicBuilders.pm @@ -4,6 +4,8 @@ extends 'Perl::Critic::Policy::DynamicMoose'; Readonly::Scalar my $EXPL => q{Prefix builder method names with an underscore}; +augment applies_to_metaclass => sub { 'Moose::Meta::Role' }; + sub violates_metaclass { my $self = shift; my $meta = shift; @@ -15,10 +17,17 @@ sub violates_metaclass { my $attributes = $meta->get_attribute_map; for my $name (keys %$attributes) { my $attribute = $attributes->{$name}; + my $builder; - next if !$attribute->has_builder; - - my $builder = $attribute->builder; + if (blessed($attribute)) { + next if !$attribute->has_builder; + $builder = $attribute->builder; + } + else { + # Roles suck :( + next if !defined($attribute->{builder}); + $builder = $attribute->{builder}; + } if ($builder !~ /^_/) { my $desc = "Builder method '$builder' of attribute '$attribute' of class '$classname' is public";