Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warn if declaring a variable in a statement modifier

Tags:

perl

I just came by the following line of code:

my $foo = $bar if $cond;

I'm going to fix this since it will of course lead to subtle bugs.

Is there a version of Perl, a module, or pragma that would warn if this type of statement was reached?

For now I'm just going to use a combination of grep and PPI to scan the codebase to fix all of these issues. Have found a total of 102 of them thus far. However, a way of automatically warning other programmers if they add a new invalid line would be helpful.

like image 849
Miller Avatar asked Aug 17 '15 18:08

Miller


1 Answers

The Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations policy in perlcritic warns about these constructions.

like image 136
mob Avatar answered Oct 13 '22 10:10

mob