Autodie愚弄了perl的语法检查

时间:2014-09-30 10:05:04

标签: perl

好像取决于perl的版本,autodie掩盖了一些语法错误。

在Perl 5.16.0中:

$ perlbrew use 5.16.0
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm 
String found where operator expected at check_netapp_pro/lib/Il/Nagios/test/xx.pm line  10, near "croak "stop""
(Do you need to predeclare croak?)
syntax error at check_netapp_pro/lib/Il/Nagios/test/xx.pm line 10, near "croak "stop""
check_netapp_pro/lib/Il/Nagios/test/xx.pm had compilation errors.

但是在5.10.1:

$ perlbrew use 5.10.1
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm 
check_netapp_pro/lib/Il/Nagios/test/xx.pm syntax OK

模块 xx.pm 是:

package Il::Nagios::Store::Attribute;
use feature ':5.10';
use strict;
use warnings;

use autodie;

#use Carp;

croak "stop" if 0;

1;
__END__

令人困惑的部分是在某些服务器上(例如CentOS 6.5,perl 5.10.1),即使模块中存在use Carp;use autodie;的缺失也会阻止脚本执行。

有人可以对此有所了解吗?你会如何对这些错误进行单元测试? (Test::Strict未检测到丢失的use Carp;语句。

1 个答案:

答案 0 :(得分:3)

感谢来自@ i-alarmed-alien的评论,我可以快速确定原因:

在我的5.10.1 perlbrew安装 autodie 安装版本2.06_01,较新的安装(perl 5.16.0)在版本2.10中使用autodie,其中修复了一个错误,泄漏了鲤鱼功能。

仅供记录:要确定 autodie (或任何其他模块)的版本,只需输入

cpan -D autodie