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