2011-10-28 33 views
29

我期待:perl的autodie.pm中的錯誤?

#!/usr/bin/perl 
use autodie; 
# autodie in effect here 
{ 
    no autodie; 
    # autodie is not in effect here 
} 
# autodie should be in effect here because of the supposedly lexical scope 
# of autodie, but this doesn't die: 
open my $i, '<', '/nonexistent'; 

我基礎上perldoc autodie,說:

的「autodie」雜注有詞法範圍,這意味着以「autodie」改變功能和 子程序只會改變他們的行爲 直到封閉塊,文件的末尾,或「EVAL」

另外,{ no autodie }(在範圍內),甚至在SYNOPSIS

use/no warnings的行爲的一部分,我希望:

#!/usr/bin/perl 
use warnings; 
{ 
    no warnings; 
} 
# This *does* generate a warning 
print undef; 

我錯過了什麼或不同意您的說法在autodie的錯誤嗎?我沒有找到在autodie buglist

This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi 

編輯任何內容:我現在已經申請a bug report

+2

在Perl v5.14.2(x86_64)中確認。 –

回答

9

我可以重現這與v5.10.0(Debian的x86_64的)和ActiveState的5.14.2。

嘗試使用this location查看錯誤報告。

編輯我測試了一些:直到bug修復規避問題,您需要重新use autodie:

use strict; 
use autodie; 

do { 
    no autodie; 
    # ... 
} while(0); 

use autodie; 

open FILE, '<', '/non-existing'; # dies again. 
+0

謝謝,是的,在我尋求一個簡單的再現腳本時,我也發現'use autodie;'再次是一種解決方法。忘了把它放在帖子中。 –

4

的簡介實際上並沒有顯示出有詞法範圍的指令,但在文檔的其他地方多次提到它。這顯然是一個錯誤。

問題變成:錯誤是否仍然存在?

$ perl -E'use autodie; say $autodie::VERSION' 
2.1001 

$ perl -we'use autodie; { no autodie; } open(my $fh, "<", "nonexistant");' 

$ perl -we'use autodie; open(my $fh, "<", "nonexistant");' 
Can't open 'nonexistant' for reading: 'No such file or directory' at -e line 1 

$ perl -we'{ use autodie; } open(my $fh, "<", "nonexistant");' 

是的,它的確如此。不過,這只是no autodie;。奇怪的是,該版本的autodie比CPAN上現有的版本更新?所以我降級並再次嘗試。

$ perl -E'use autodie; say $autodie::VERSION' 
2.10 

$ perl -we'use autodie; { no autodie; } open(my $fh, "<", "nonexistant");' 

$ perl -we'use autodie; open(my $fh, "<", "nonexistant");' 
Can't open 'nonexistant' for reading: 'No such file or directory' at -e line 1 

$ perl -we'{ use autodie; } open(my $fh, "<", "nonexistant");' 

錯誤可以使用autodie的bug tracker提交。