From: Shawn M Moore Date: Tue, 28 Apr 2009 08:08:12 +0000 (-0400) Subject: Fix element guessing. urg. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1e6decf8a5d422a28f880f62e61953d4f988d0c2;p=gitmo%2FPerl-Critic-Dynamic-Moose.git Fix element guessing. urg. --- diff --git a/lib/Perl/Critic/Policy/DynamicMoose.pm b/lib/Perl/Critic/Policy/DynamicMoose.pm index 6b0f64d..c0c9036 100644 --- a/lib/Perl/Critic/Policy/DynamicMoose.pm +++ b/lib/Perl/Critic/Policy/DynamicMoose.pm @@ -4,21 +4,27 @@ use MooseX::NonMoose; extends 'Perl::Critic::DynamicPolicy'; has document => ( - is => 'rw', - isa => 'PPI::Document', + is => 'rw', + isa => 'PPI::Document', + handles => [qw/ppi_document/], ); sub applies_to { 'PPI::Document' } sub applies_to_metaclass { 'Class::MOP::Class' } around violation => sub { - my $orig = shift; - my $self = shift; - my $desc = shift; - my $expl = shift; - my $doc = shift || $self->document; + my $orig = shift; + my $self = shift; + my $desc = shift; + my $expl = shift; + my $element = shift; + + if (!$element) { + my $doc = $self->ppi_document; + $element = $doc->find('PPI::Element')->[0]; + } - return $self->$orig($desc, $expl, $doc, @_); + return $self->$orig($desc, $expl, $element, @_); }; sub violates_dynamic {