X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FPerl%2FCritic%2FPolicy%2FDynamic%2FNoIndirect.pm;h=068ab88d1ff81018234934d13bea9d2f80c71c54;hb=6e8dbf3b02e4df3a7304b7acbe47037575fc952d;hp=3769d30fd9c7d084336710312b8b34e0493d4508;hpb=b9f3c06e4b9574e706c62e7645a9236b37b26953;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 3769d30..068ab88 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.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 DESCRIPTION @@ -58,24 +58,25 @@ sub violates_dynamic { my @errs; my $wrapper = <<" WRAPPER"; - { return; package main; - no indirect hook => sub { push \@errs, [ \@_ ] }; - { - ; + my \$hook; + BEGIN { \$hook = sub { push \@errs, [ \@_ ] } } + no strict; + no warnings; + no indirect hook => \$hook; + do { #line 1 "$file" $src } - } WRAPPER { local ($@, *_); eval $wrapper; ## no critic - if ($@) { + if (my $err = $@) { require Carp; - Carp::confess("Couldn't compile the source wrapper: $@"); + Carp::croak("Couldn't compile the source wrapper: $err"); } } @@ -118,7 +119,7 @@ sub violates_dynamic { =head1 CAVEATS -The uses of the L pragma inside the auditted code take precedence over this policy. +The uses of the L pragma inside the audited 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. @@ -130,7 +131,14 @@ L 5.8, L. L, L. -L. +L 0.20. + +=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 @@ -151,7 +159,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2009 Vincent Pit, all rights reserved. +Copyright 2009,2010 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.