简体   繁体   English

perl5方法测试“可能”在新版本中无法正常工作

[英]perl5 method test “can” not working correctly in new version

In perl 5.8 在perl 5.8中

perl  -e ' print "a" if AXXXXXXXXXXXXX::->can("isa");'
perl  -e ' print "a" if AXXXXXXXXXXXXX->can("isa");'

print "nothing" , means method test failed; 打印“无”,表示方法测试失败;

In perl 5.17 在perl 5.17中

perl  -e ' print "a" if AXXXXXXXXXXXXX::->can("isa");'
perl  -e ' print "a" if AXXXXXXXXXXXXX->can("isa");'

print "a", means method test succeed; 打印“a”,表示方法测试成功;

I want to know why difference ? 我想知道为什么不同?

and why un-esixt and un-loaded module "AXXXXXXXXX" test pass in new version of perl ? 以及为什么un-esixt和un-loaded模块“AXXXXXXXXX”测试在新版本的perl中传递?

very thank you :) 非常感谢 :)

From perldoc perl5180delta : 来自perldoc perl5180delta

"$class->can", "$class->isa", and "$class->DOES" now return correct results, regardless of whether that package referred to by $class exists [perl #47113]. “$ class-> can”,“$ class-> isa”和“$ class-> DOES”现在返回正确的结果,无论$ class引用的包是否存在[perl#47113]。

This change was introduced in order to fix a long-open bug report regarding UNIVERSAL::can . 引入此更改是为了修复有关UNIVERSAL::can的长期错误报告。 The change does result in arguably incompatible changes in behavior, but based on existing discussion, the change in behavior is not seen as a bug and is not likely to be reverted. 这种变化确实导致了行为上可能存在不兼容的变化,但基于现有的讨论,行为的变化不会被视为错误,也不可能被还原。

perl #47113 documents the original bug report and the recent fix perl#47113记录了原始的bug报告和最近的修复

perl #118513 is a bug reporting the behavior you observed -- closed as rejected perl#118513是一个报告你观察到的行为的错误 - 关闭被拒绝

It is very likely that there is another means to accomplish what you are attempting do with the code examples in your question. 很可能还有另一种方法可以完成您尝试使用问题中的代码示例所做的事情。 I'd recommend searching for that which you are trying to accomplish. 我建议你搜索一下你想要完成的事情。

If you're trying to test to see if a specific module is loaded, you can use something similar to the approach adopted by Params::Validate::Dependencies in response to this change: 如果您正在尝试测试是否加载了特定模块,则可以使用类似于Params :: Validate :: Dependencies采用的方法来响应此更改:

no strict 'refs'
unless(@{"${class}::ISA"}) [...]

There's likely another way -- again, search for what you're trying to accomplish, now that you know about this change to Perl. 可能还有另一种方式 - 再次,搜索你想要完成的事情,现在你已经了解了Perl的这一变化。

can was buggy. can跑车。 As you're reported, can would report that some modules namespaces didn't have a method name isa . 正如您所报告的, can报告某些模块名称空间没有方法名称isa

>perl5.16.3 -E"say 'xxx'->can('isa') ? q{can} : q{can't}"
can't

Yet all namespaces have such a method. 然而,所有命名空间都有这样的方法。

>perl5.16.3 -E"say eval { 'xxx'->isa('yyy'); 1 } ? q{can} : q{can't}"
can

This was fixed in 5.18.0 这被固定在5.18.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Perl:为什么此表达式不适用于新版本的Perl? - Perl: Why is this expression not working with the new version of Perl? 如何在路径中没有子版本号的情况下安装Perl? (lib / perl5 / 5.XY-> lib / perl5 / 5.X) - How to install Perl without sub-version number in path? (lib/perl5/5.X.Y -> lib/perl5/5.X) 无法在/usr/share/perl5/LWP/UserAgent.pm第563行的未定义值上调用方法“request” - Can't call method “request” on an undefined value at /usr/share/perl5/LWP/UserAgent.pm line 563 无法在@INC 中找到 DBD/ODBC.pm(@INC 包含:/usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor。 ) - Can't locate DBD/ODBC.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor.) Perl DateTime“is_dst()”方法无法正常工作 - Perl DateTime “is_dst()” method not working correctly 在@INC 中找不到 CPAN.pm(@INC 包含:/usr/local/lib/perl5 /usr/local/share/perl5 - Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 Perl5 =(等于)运算符优先级 - Perl5 = (equals) operator precedence 用空白元素替换perl5 - perl5 substitution with blank elements Perl5中的注释使程序崩溃? - Comments in Perl5 crash the program? 在Perl5中实现功能切换 - Implementing Feature Toggles in Perl5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM