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