Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 33839
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: lammel [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.080
Fixed in: (no value)



Subject: Always unpack @_ first reported wrong for simple sub
When running perlcritic (theme: core, severity: 3) against the attached file (Catalyst::Plugin::Session::State::QpAPI.pm) always the always unpack @_ error is reported. Here is the cli output: <code> sh$ perlcritic --profile t/perlcriticrc lib/Catalyst/Plugin/Session/State/QpAPI.pm -v 9 [Subroutines::RequireArgUnpacking] Always unpack @_ first at line 11, near 'sub get_session_id {'. (Severity: 4) </code> Also tested with Perl::Critic 1.081_006 with the same result.
Subject: QpAPI.pm
package Catalyst::Plugin::Session::State::QpAPI; use base qw/Catalyst::Plugin::Session::State/; use strict; use warnings; use NEXT; our $VERSION = "0.1"; sub get_session_id { my ($c) = @_; if ($c->request->path =~ /^qpapi\//x) { my $sid = $c->request->param("sessionid") || ""; if ($sid) { $c->log->debug(qq/Found sessionid "$sid" in qpapi request/) if $c->debug; return $sid if $sid; } } return $c->NEXT::get_session_id(@_); } 1; __END__ =pod =head1 NAME Catalyst::Plugin::Session::State::QpAPI - Maintain session IDs using post params for qpapi path. =head1 SYNOPSIS use Catalyst qw/Session Session::State::QpAPI/; =head1 DESCRIPTION In order for L<Catalyst::Plugin::Session> to work the session ID needs to be stored on the client, and the session data needs to be stored on the server. This plugin allows retrieval of the sessionid in the post param sessionid. =head1 METHODS =over 4 =item get_session_id =back =head1 SEE ALSO L<Catalyst>, L<Catalyst::Plugin::Session>. L<Catalyst::Plugin::Session::State::Cookie> =head1 AUTHORS Roland Lammel <lt>rl@brabbel.net<gt> =head1 COPYRIGHT This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Wed, 05 Mar 2008 17:00:04 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Roland Lammel via RT wrote: Show quoted text
> When running perlcritic (theme: core, severity: 3) against the attached > file (Catalyst::Plugin::Session::State::QpAPI.pm) always the always > unpack @_ error is reported.
Thanks for this. I get the same result. The PPI DOM for the code looks fine, so it appears to be our problem.
On Wed Mar 05 18:00:49 2008, clonezone wrote: Show quoted text
> Roland Lammel via RT wrote:
> > When running perlcritic (theme: core, severity: 3) against the
> attached
> > file (Catalyst::Plugin::Session::State::QpAPI.pm) always the always > > unpack @_ error is reported.
> > Thanks for this. I get the same result. The PPI DOM for the code > looks fine, so it appears to be our problem.
After a little further testing with perlcritic I found that the critic is triggered by passing @_ in the sub (at the end of the get_session_id sub). So the following code actually triggers the critic: return $c->NEXT::get_session_id(@_); After removing it, or replacing it with I tested it, and removing the @_ now shows the file to be ok, no critic is raised anymore. That probably does not make sense, as passing to SUPER or NEXT is usually done with the same sub params.
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Wed, 05 Mar 2008 17:25:35 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Roland Lammel via RT wrote: Show quoted text
> After a little further testing with perlcritic I found that the critic > is triggered by passing @_ in the sub (at the end of the get_session_id > sub). > > So the following code actually triggers the critic: > return $c->NEXT::get_session_id(@_); > > After removing it, or replacing it with I tested it, and removing the @_ > now shows the file to be ok, no critic is raised anymore. > > That probably does not make sense, as passing to SUPER or NEXT is > usually done with the same sub params.
Ah. Hadn't noticed the other usage of @_. Yeah, this Policy doesn't make any exceptions. So, here's a question: should we support EVERY()? I think we should do this as an exceptions parameter to the Policy.
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Thu, 6 Mar 2008 00:34:06 +0100
To: bug-Perl-Critic [...] rt.cpan.org
From: "Roland Lammel" <lammel [...] cpan.org>
On Thu, Mar 6, 2008 at 12:25 AM, Elliot Shank via RT < bug-Perl-Critic@rt.cpan.org> wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=33839 > > > Roland Lammel via RT wrote:
> > After a little further testing with perlcritic I found that the critic > > is triggered by passing @_ in the sub (at the end of the get_session_id > > sub). > > > > So the following code actually triggers the critic: > > return $c->NEXT::get_session_id(@_); > > > > After removing it, or replacing it with I tested it, and removing the @_ > > now shows the file to be ok, no critic is raised anymore. > > > > That probably does not make sense, as passing to SUPER or NEXT is > > usually done with the same sub params.
> > Ah. Hadn't noticed the other usage of @_. Yeah, this Policy doesn't make > any exceptions. > > So, here's a question: should we support EVERY()? > > I think we should do this as an exceptions parameter to the Policy. >
Guess that would make sense, as this kind of code (repassing all params to SUPER) is quite common and it's a lot of work to add ## no critic Subroutines;;RequireArgUnpacking to every sub that does that ;-) Although I don't really understand what you mean by EVERY() it is probably the right thing, if it allows to pass the complete @_ array to another sub (so delegation and passing up in inheritance would be allowed).
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Wed, 05 Mar 2008 18:01:45 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Roland Lammel via RT wrote: Show quoted text
> Guess that would make sense, as this kind of code (repassing all > params to SUPER) is quite common and it's a lot of work to add ## no > critic Subroutines;;RequireArgUnpacking to every sub that does that > ;-) > > Although I don't really understand what you mean by EVERY() it is > probably the right thing, if it allows to pass the complete @_ array > to another sub (so delegation and passing up in inheritance would be > allowed).
I just said it because it's part of the NEXT module. I think we should just add an exceptions parameter to the Policy with a default value of SUPER. Then you can just add NEXT to that list. And if anyone comes up with any other fun flow control modules, they can add it to the list. So, here's what I think we should have it work: $self->SUPER::foo(@_) # ok $self->SUPER::foo(@_, 'blah') # not ok $self->SUPER::foo(bar(@_)) # not ok Basically, if there's anything other than just @_ in the parameters, then it's still a violation.
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Thu, 6 Mar 2008 02:33:09 +0100
To: bug-Perl-Critic [...] rt.cpan.org
From: "Roland Lammel" <lammel [...] cpan.org>
On Thu, Mar 6, 2008 at 1:02 AM, Elliot Shank via RT < bug-Perl-Critic@rt.cpan.org> wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=33839 > > > Roland Lammel via RT wrote:
> > Guess that would make sense, as this kind of code (repassing all > > params to SUPER) is quite common and it's a lot of work to add ## no > > critic Subroutines;;RequireArgUnpacking to every sub that does that > > ;-) > > > > Although I don't really understand what you mean by EVERY() it is > > probably the right thing, if it allows to pass the complete @_ array > > to another sub (so delegation and passing up in inheritance would be > > allowed).
> > I just said it because it's part of the NEXT module. > > I think we should just add an exceptions parameter to the Policy with a > default value of SUPER. Then you can just add NEXT to that list. And if > anyone comes up with any other fun flow control modules, they can add it to > the list.
I think it would be better to include the known inheritance modules (NEXT, Class::C3, SUPER), but that still would not solve the problem in case of delegation. I have some modules, that simply delegate the complete call to another module's class or object method. That would still be not possible. Is there anything wrong with using just @_ once in the sub with no other parameters (as proposed below) and not limiting it to SUPER or similar? Show quoted text
> > > So, here's what I think we should have it work: > > $self->SUPER::foo(@_) # ok > $self->SUPER::foo(@_, 'blah') # not ok > $self->SUPER::foo(bar(@_)) # not ok > > Basically, if there's anything other than just @_ in the parameters, then > it's still a violation.
Sound great.
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Wed, 05 Mar 2008 20:30:16 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Roland Lammel via RT wrote: Show quoted text
> I think it would be better to include the known inheritance modules > (NEXT, Class::C3, SUPER)
I'll go along with NEXT because it's in core, but nothing else. I'm not going to predict what else out there. And, again, you can always configure it. Show quoted text
> but that still would not solve the problem in case of delegation. I > have some modules, that simply delegate the complete call to another > module's class or object method. That would still be not possible. Is > there anything wrong with using just @_ once in the sub with no > other parameters (as proposed below) and not limiting it to SUPER or > similar?
There's already the short_subroutine_statements parameter to the Policy. I think that's good enough.
Subject: Re: [rt.cpan.org #33839] Always unpack @_ first reported wrong for simple sub
Date: Wed, 5 Mar 2008 20:36:04 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
I recommend that you change the code to this: sub get_session_id { ## no critic (Unpack) Chris On Mar 5, 2008, at 5:11 PM, Roland Lammel via RT wrote: Show quoted text
> > Queue: Perl-Critic > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33839 > > > On Wed Mar 05 18:00:49 2008, clonezone wrote:
>> Roland Lammel via RT wrote:
>>> When running perlcritic (theme: core, severity: 3) against the
>> attached
>>> file (Catalyst::Plugin::Session::State::QpAPI.pm) always the always >>> unpack @_ error is reported.
>> >> Thanks for this. I get the same result. The PPI DOM for the code >> looks fine, so it appears to be our problem.
> > > After a little further testing with perlcritic I found that the critic > is triggered by passing @_ in the sub (at the end of the > get_session_id > sub). > > So the following code actually triggers the critic: > return $c->NEXT::get_session_id(@_); > > After removing it, or replacing it with I tested it, and removing > the @_ > now shows the file to be ok, no critic is raised anymore. > > That probably does not make sense, as passing to SUPER or NEXT is > usually done with the same sub params.
In progress Tom Wyant
Proposed fix committed as svn revision 3145. The revised RequireArgUnpacking allows "$object->SUPER::foo(@_)" and "$object->NEXT::foo(@_)". Configuration option 'allow_delegation_to' has been added to allow delegation to other places. Tom Wyant
This has been completed and released in Perl-Critic-1.097_002. http://search.cpan.org/~elliotjs/Perl-Critic-1.097_002 Thank you for submitting this ticket.