http://www.perlmonks.org?node_id=655915


in reply to Perl best practices fanatism

I like Perl::Critic, but once in a while I run across a policy that's completely wrong. My personal example today is the one to prohibit conditionals in declarations. That's right for lexicals, because of the unwarned and almost always entirely unwanted pseudo-static behavior exhibited through Perl 5.8... but the policy bafflingly warns about the construct for local variables, which do not exhibit this problem at all.

If I could remember the name of the policy, I'd file a bug against it.

Replies are listed 'Best First'.
Re^2: Perl best practices fanatism
by xdg (Monsignor) on Dec 09, 2007 at 04:38 UTC

    I already reported that bug and it was (supposedly) fixed in 1.079_001.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: Perl best practices fanatism
by perrin (Chancellor) on Dec 09, 2007 at 02:34 UTC
    It's Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations. I remember because I requested it. I've never heard of this exception for local though. What's the story?

      I have testing code (Parrot::Test, for example) that sometimes needs to mark a test as TODO, but for various reasons can't set the appropriate package variable. In the case of Parrot, this is because the code being tested is not Perl. Thus the library contains a line something like:

      local ${ $package . '::TODO' } = $opts{todo} if $opts{todo};

      This construct is very different than the conditional declaration of a lexical variable because local only controls the visibility of a symbol's binding. The unbinding always occurs at the end of the scope if the conditional is true. Unlike lexical bindings, the false condition does not interfere with unbinding.

      xdg is right, and it does appear fixed. Nice!