X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FPerl%2FCritic%2FPolicy%2FDynamic%2FNoIndirect.pm;h=3233efcfa555745b1e118a5e45401efb3336907f;hb=4b561e89d1b18f98e50315fed79705e4b4c26edd;hp=11b9b5c6fe8ba5bc28f08c3a6d51bcd080d5d784;hpb=96aa3e9b451af479ad8855ff862a016a74e98742;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 11b9b5c..3233efc 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 @@ -34,6 +34,12 @@ sub default_severity { $SEVERITY_HIGH } sub default_themes { qw/dynamic maintenance/ } sub applies_to { 'PPI::Document' } +my $tag_obj = sub { + my $obj = '' . $_[0]; + $obj = '{' if $obj =~ /^\s*\{/; + $obj; +}; + sub violates_dynamic { my ($self, undef, $doc) = @_; @@ -78,7 +84,7 @@ sub violates_dynamic { for (@errs) { my ($obj, $meth, $line) = @$_[0, 1, 3]; $line -= $offset; - my $tag = join "\0", $line, $meth, $obj; + my $tag = join "\0", $line, $meth, $tag_obj->($obj); push @{$errs_tags{$tag}}, [ $obj, $meth ]; } @@ -87,7 +93,7 @@ sub violates_dynamic { my $pos = $elt->location; return 0 unless $pos; - my $tag = join "\0", $pos->[0], $elt, $elt->snext_sibling; + my $tag = join "\0", $pos->[0], $elt, $tag_obj->($elt->snext_sibling); if (my $errs = $errs_tags{$tag}) { push @violations, do { my $e = pop @$errs; push @$e, $elt; $e }; delete $errs_tags{$tag} unless @$errs; @@ -100,14 +106,23 @@ sub violates_dynamic { return map { my ($obj, $meth, $elt) = @$_; + $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"$obj\""; $self->violation( - "Indirect call of method \"$meth\" on object \"$obj\"", + "Indirect call of method \"$meth\" on $obj", "You really wanted $obj\->$meth", $elt, ); } @violations; } +=head1 CAVEATS + +The uses of the L pragma inside the auditted code take precedence over this policy. +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.