On Fri Aug 24 00:49:38 2012, jeff@imaginative-software.com wrote:
Show quoted text>
> On Aug 23, 2012, at 8:27 PM, Tom Wyant via RT wrote:
>
> > Based on my third thought above (that the real problem is that the
> logic
> > to allow testing the size of the argument list is not comprehensive
> > enough), I have committed some changes that may help.
>
> I understood the problem differently. The argument to finally is a
> code ref that is given some arguments when invoked. Basically, it
> is a subroutine declaration within a subroutine declaration. But
> PPI doesn't see it that way, because it doesn't see the 'sub'
> keyword. So the policy sees the @_ inside the finally block as the
> arguments that were passed to the enclosing named subroutine. But
> they aren't.
>
> So strictly speaking, the sample code is fully compliant. Within the
> finally "subroutine", @_ is handled immediately. Does that make
> sense?
You are right that the @_ in the finally() block is not the same as the
@_ at the top of the sub. And Perl::Critic seems to be dimly aware of
this, as shown by the fact that I have to run -noprof to duplicate the
error, apparently because my .perlcriticrc has
'short_subroutine_statements = 3'.
But when I run Perl::Critic 1.18 against
sub my_method {
print 'No error' unless (@_);
return;
}
which I believe to be structurally equivalent to the original poster's
code, I get
$ perlcritic --single ArgUnpacking -noprof fubar.pl
Always unpack @_ first at line 1, column 1. See page 178 of PBP.
(Severity: 4)
Do you get something different? Or is there something wrong with my example?
I think the error is because 'unless( @_ )' is neither an assignment nor
a shift. I suspect that the error could also (in this specific case) be
suppressed by 'allow_delegation_to = unless', but I have not investigated.