choroba has asked for the wisdom of the Perl Monks concerning the following question:

After switching to Function::Parameters, I noticed Perl::Critic no longer worked. For example, for the old fashioned
sub foo { $_[0] + 1 }
perlcritic -1 outputs
Always unpack @_ first at line 22, column 1. See page 178 of PBP. (S +everity: 4) Subroutine "foo" does not end with "return" at line 22, column 1. See + page 197 of PBP. (Severity: 4)

but for the equivalent

use Function::Parameters; fun foo ($x) { $x + 1 }
it doesn't say anything.

I've found a partial workaround: running perlcritic on the output of B::Deparse instead of the source itself. It reports lots of sins committed by Function::Parameters themselves (e.g. Magic variable "$^H" should be assigned as "local" at line 14, column 44. See pages 81,82 of PBP.) but seems to work.

Unfortunately, it gets more complex when Types::Standard are added to the mix.

use Function::Parameters; use Types::Standard qw( Num ); fun foo (Num $x) { $x + 1 }
The code doesn't look much more complicated, but running perl -MO=Deparse on it just hangs. Output of strace ends with endlessly repeating lines:
mmap(NULL, 192512, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1 +, 0) = 0x7fe772fdf000 mremap(0x7fe771772000, 532480, 536576, MREMAP_MAYMOVE) = 0x7fe77177200 +0 brk(0x49ac000) = 0x49ac000 brk(0x49cd000) = 0x49cd000 mremap(0x7fe771772000, 536576, 540672, MREMAP_MAYMOVE) = 0x7fe77177200 +0 brk(0x49ee000) = 0x49ee000 brk(0x49ed000) = 0x49ed000 brk(0x4a0e000) = 0x4a0e000 brk(0x4a2f000) = 0x4a2f000 mremap(0x7fe771772000, 540672, 544768, MREMAP_MAYMOVE) = 0x7fe77177200 +0 ...
The perl process seems to grow in memory very slowly at the same time.

Has anyone succeeded in linting a code that uses the above mentioned modules? Tips, tricks, suggestions welcome.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re: Function::Parameters, Types::Standard, and Perl::Critic
by haukex (Archbishop) on Feb 16, 2019 at 06:59 UTC

    At least for the first part of your question, I guess it's because PPI, which Perl::Critic uses internally, no longer recognizes the code as a sub and so those policies don't apply.

    For the second part, I can confirm the same behavior, but I can't say in which of the modules this is a bug...

Re: Function::Parameters, Types::Standard, and Perl::Critic
by tobyink (Canon) on Feb 17, 2019 at 01:06 UTC

    Types::Standard will use XS to implement a lot of checks when possible. I don't know all the details of how Function::Parameters employs Types::Standard, but you may be creating a situation where you're trying to deparse an XS sub, which would be impossible. You could set the "PERL_TYPE_TINY_XS" environment variable to "0" before running and see if that makes a difference.

      Unfortunately, it still hangs :-(.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]