X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FPerl%2FCritic%2FPolicy%2FDynamic%2FNoIndirect.pm;h=3769d30fd9c7d084336710312b8b34e0493d4508;hb=b9f3c06e4b9574e706c62e7645a9236b37b26953;hp=556ecc6013c209778fce30672b363fd3b85682a0;hpb=05870b723b862a0daadd62a71b81e3e8bca7f881;p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git diff --git a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm index 556ecc6..3769d30 100644 --- a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm +++ b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm @@ -11,11 +11,11 @@ Perl::Critic::Policy::Dynamic::NoIndirect - Perl::Critic policy against indirect =head1 VERSION -Version 0.03 +Version 0.04 =cut -our $VERSION = '0.03'; +our $VERSION = '0.04'; =head1 DESCRIPTION @@ -43,19 +43,20 @@ my $tag_obj = sub { sub violates_dynamic { my ($self, undef, $doc) = @_; - my $src; - + my ($src, $file); if ($doc->isa('PPI::Document::File')) { - my $file = $doc->filename; + $file = $doc->filename; open my $fh, '<', $file or do { require Carp; Carp::confess("Can't open $file for reading: $!") }; $src = do { local $/; <$fh> }; } else { - $src = $doc->serialize; + $file = '(eval 0)'; + $src = $doc->serialize; } + $file =~ s/(? sub { push \@errs, [ \@_ ] }; { ; +#line 1 "$file" $src } } @@ -83,7 +85,6 @@ sub violates_dynamic { my %errs_tags; for (@errs) { my ($obj, $meth, $line) = @$_[0, 1, 3]; - $line -= $offset; my $tag = join "\0", $line, $meth, $tag_obj->($obj); push @{$errs_tags{$tag}}, [ $obj, $meth ]; } @@ -121,6 +122,8 @@ The uses of the L pragma inside the auditted code take precedence over Hence no violations will be reported for indirect method calls that are located inside the lexical scope of C or C<< no indirect hook => ... >>. Occurrences of C won't be a problem. +Since the reports generated by L are remapped to the corresponding L objects, the order in which the violations are returned is different from the order given by L : the former is the document order (top to bottom, left to right) while the latter is the optree order (arguments before function calls). + =head1 DEPENDENCIES L 5.8, L.