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: 79644
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: mjy [...] geizhals.at
Cc:
AdminCc:

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



Subject: All 13 standard Subroutine policies ignore anonymous subs
Date: Fri, 14 Sep 2012 14:53:01 +0200
To: bug-Perl-Critic [...] rt.cpan.org
From: Marinos Yannikos <mjy [...] geizhals.at>
Perl::Critic 1.118 This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi Issue: subroutine policies (Perl::Critic::Policy::Subroutines::*) are not checked for anonymous subs. This is particularly bad for code with callbacks and web frameworks that use "sinatra" style routes, e.g. Mojolicious, where such patterns are common: get '/' => sub { ... }; The reason why Perl::Critic policies ignore anonymous subs is that they only check for PPI::Statement::Sub, which only supports named subs (see perldoc PPI::Statement::Sub). Anonymous subs are parsed by PPI into PPI::Token::Word 'sub' PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } Consequently, all 13 standard policies should be fixed to search for both variants since for all matters of style checking, anonymous subs are equivalent to named subs (right?). Regards, Marinos
Subject: Re: [rt.cpan.org #79644] All 13 standard Subroutine policies ignore anonymous subs
Date: Fri, 14 Sep 2012 08:49:49 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On Sep 14, 2012, at 5:53 AM, Marinos Yannikos via RT wrote: Show quoted text
> Consequently, all 13 standard policies should be fixed to search for > both variants since for all matters of style checking, anonymous subs > are equivalent to named subs (right?).
Not all of them actually make sense for an anonymous sub (like ProtectPrivateSubs). And some of them *do* work for anonymous subs (like ProhibitExplicitReturnUndef), but mostly by coincidence. The others probably *could* work for anonymous subs, but we have punted. So I'll use this ticket as a reminder to investigate. Given the rising popularity of Moose, Dancer, Mojo, etc. it is probably time to make these policies work properly for anonymous subs. Thanks for reminding us! -Jeff
Subject: Re: [rt.cpan.org #79644] All 13 standard Subroutine policies ignore anonymous subs
Date: Fri, 14 Sep 2012 19:48:09 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
The problem is that PPI doesn't parse anonymous subs as subs because Adam was too worried about "sub" not being a keyword. This is a case where I think he was being way to conservative. If PPI were changed, then I think a lot of Policies would suddenly start checking a lot more code. ppidump '$x = sub { 1 }' PPI::Document PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 6, 6 ] PPI::Token::Word 'sub' PPI::Structure::Block { ... } PPI::Statement [ 1, 12, 12 ] PPI::Token::Number '1'