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

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)
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.

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.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


In reply to Quieting perlcritic when passing @_ to Params::Validate by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.