From: Shawn M Moore Date: Tue, 28 Apr 2009 08:46:02 +0000 (-0400) Subject: Switch to tracking new metaclasses, instead of using PPI X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3450216476688d85a5d71a59fce70921b2dc1826;p=gitmo%2FPerl-Critic-Dynamic-Moose.git Switch to tracking new metaclasses, instead of using PPI --- diff --git a/lib/Perl/Critic/Policy/DynamicMoose.pm b/lib/Perl/Critic/Policy/DynamicMoose.pm index e4f66fb..729094b 100644 --- a/lib/Perl/Critic/Policy/DynamicMoose.pm +++ b/lib/Perl/Critic/Policy/DynamicMoose.pm @@ -32,12 +32,13 @@ sub violates_dynamic { my $doc = shift; $self->document($doc); - $self->compile_document; - my @packages = $self->find_packages; + my $old_packages = $self->find_packages; + $self->compile_document; + my @new_packages = $self->new_packages($old_packages); my @violations; - for my $package (@packages) { + for my $package (@new_packages) { my $meta = Class::MOP::class_of($package) or next; @@ -63,10 +64,22 @@ sub compile_document { sub find_packages { my $self = shift; - my $doc = $self->document; + return [ Class::MOP::get_all_metaclass_names ]; +} + +sub new_packages { + my $self = shift; + my $old = shift; + my @new; + my %seen; + + $seen{$_} = 1 for @$old; + + for (@{ $self->find_packages }) { + push @new, $_ if !$seen{$_}++; + } - return map { $_->namespace } - @{ $doc->find('PPI::Statement::Package') || [] }; + return @new; } no Moose;