X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FPerl%2FCritic%2FPolicy%2FDynamic%2FNoIndirect.pm;h=b14ecf53f801d2d4bb5af05352085b8e60f7ffb1;hb=9a658054acd1d628ba4f98c49127fcdf8fd1512b;hp=411da99dee0bc53e9dcc15e0cc0127f7d19694a1;hpb=03dc7499c344c785170db4d4e8452a9eb8e03a1c;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 411da99..b14ecf5 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 ]; } @@ -131,6 +132,13 @@ L, L. L. +=head1 SEE ALSO + +L is a L policy that statically checks for indirect constructs. +But to be static it has to be very restricted : you have to manually specify which subroutine names are methods for which the indirect form should be forbidden. +This can lead to false positives (a subroutine with the name you gave is defined in the current scope) and negatives (indirect constructs for methods you didn't specify). +But you don't need to actually compile (or run, as it's more or less the same thing) the code. + =head1 AUTHOR Vincent Pit, C<< >>, L.