有一个简单的模块
package Rrr;
use 5.014;
use warnings;
use namespace::sweep;
use Moo;
use Method::Signatures::Simple;
BEGIN {
our $VERSION = '0.0.1';
}
has 'root' => (
is => 'rw',
default => 'root'
);
method func {
say 'This is the func method from ' . __PACKAGE__ . ' with value: ', $self->root;
}
1;perlcritic -1说
Code is not tidy at line 1, column 1. See page 33 of PBP. (Severity: 1)
Module does not end with "1;" at line 17, column 1. Must end with a recognizable true value. (Severity: 4)
Return value of flagged function ignored - say at line 18, column 5. See pages 208,278 of PBP. (Severity: 1)如何让评审团快乐?
基于@toolic的评论编辑
是的,整洁有助于解决第一个问题(但是Code is not tidy at line 1, column 1.不是很有帮助的信息),因为差异是:
13c13
< is => 'rw',
---
> is => 'rw',
18c18,19
< say 'This is the func method from ' . __PACKAGE__ . ' with value: ', $self->root;
---
> say 'This is the func method from ' . __PACKAGE__ . ' with value: ',
> $self->root;但还是得到了:
Module does not end with "1;" at line 17, column 1. Must end with a recognizable true value. (Severity: 4)
Return value of flagged function ignored - say at line 18, column 5. See pages 208,278 of PBP. (Severity: 1)我的伪君子:
$ perlcritic --version
1.125发布于 2015-07-16 16:29:40
看起来,来自method的Method::Signatures::Simple关键字正在抛出评论词。请注意PPI解析以下程序的不同之处:
$ tools/ppidump 'method foo { 1 } 1;'
PPI::Document
PPI::Statement
[ 1, 1, 1 ] PPI::Token::Word 'method'
[ 1, 8, 8 ] PPI::Token::Word 'foo'
PPI::Structure::Block { ... }
PPI::Statement
[ 1, 14, 14 ] PPI::Token::Number '1'
[ 1, 18, 18 ] PPI::Token::Number '1'
[ 1, 19, 19 ] PPI::Token::Structure ';'
$ tools/ppidump 'sub foo { 1 } 1;'
PPI::Document
PPI::Statement::Sub
[ 1, 1, 1 ] PPI::Token::Word 'sub'
[ 1, 5, 5 ] PPI::Token::Word 'foo'
PPI::Structure::Block { ... }
PPI::Statement
[ 1, 11, 11 ] PPI::Token::Number '1'
PPI::Statement
[ 1, 15, 15 ] PPI::Token::Number '1'
[ 1, 16, 16 ] PPI::Token::Structure ';'当使用method时,整个程序被视为一个语句;当使用sub时,1;被视为一个单独的语句。
为了使评审员保持安静,您可以在方法的结束大括号之后添加分号:
method func {
...
};
1;或者另一种
method func {
...
}
;1;然而,我认为amon在评论中提出了一个很好的观点:
对于这类问题,perl批评家无法处理语法扩展(例如方法signatures...Due ),我倾向于在语法扩展和perlcritic之间进行选择--在大多数情况下,我不得不更倾向于静态分析而不是语法糖。
https://stackoverflow.com/questions/31457885
复制相似问题