I'm a fan of perlcritic, but it complains bitterly when I write code that passes @_ to Params::Validate.
#!/usr/bin/perl -w # # Params::Validate test code. use strict; use Params::Validate qw /:all/; { print "Setting validation options to allow extra parameters.\n"; validation_options( allow_extra => 1 ); print "Calling baz ..\n"; baz( name => 'Alex', unknown => "scary" ); baz( name => 'Alex', height => 181, unknown => "scary" ); print "Back from baz!\n"; } sub baz { print 'On entry: @_ has: ' . join(':',@_) . "\n"; my %p = validate( @_, { name => 1, height => { default => 200 } } +); print "Validation baz succeeded, paramater hash is:\n"; foreach my $key ( keys %p ) { print "--> $key: $p{$key}\n"; } }
Running $ perlcritic -4 pv.pl against this produces
I had an idea that the allow_delegation idea from http://search.cpan.org/~elliotjs/Perl-Critic-1.109/lib/Perl/Critic/Policy/Subroutines/RequireArgUnpacking.pm (while not really understanding what it does), might work: I was hoping that perlcritic would say, "Oh, passing @_ to the delegate (Params::Validate) is OK." Googling for 'perlcritic allow_delegation' produces three results, one for the CPAN page and two that are source files. So I probably don't understand how this feature works.Code before warnings are enabled at line 9, column 1. See page 431 of + PBP. (Severity: 4) Always unpack @_ first at line 19, column 1. See page 178 of PBP. (S +everity: 4) Subroutine "baz" does not end with "return" at line 19, column 1. See + page 197 of PBP. (Severity: 4)
Is there a way to get perlcritic to not complain if I pass @_ to Params::Validate?
Update: It looks like this page contains the delta that added the feature to perlcritic, and it only opens the door wide enough to allow calls within the class structure, and not (as I had hoped) to externals like Params::Validate. I may have to disable that criticism altogether, unless anyone has a better suggestion.
Update 2: After I posted this, I continued searching (using Google), and after about 15 minutes of trying a variety of search terms I was stunned to see *this post* included in the search results. After *no more* than 15 minutes. Wow.
In reply to Quieting perlcritic when passing @_ to Params::Validate by talexb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |