Perl 5中的parent和base有什么区别? [英] What is the difference between parent and base in Perl 5?
问题描述
似乎有一个名为 parent
的新编译指示与 base
大致相同. parent
如何保证新的(非核心)模块?我想念什么吗?
There appears to be a new pragma named parent
that does roughly the same thing as base
. What does parent
do that warrants a new (non-core) module? I am missing something?
推荐答案
base
试图做太多事情–自动处理正在加载的模块,但也允许从已加载的类建立继承(可能是从名称不基于模块名称的文件中继承).为了使它起作用,有些黑客在某些情况下导致了令人惊讶的结果.并没有破坏向后兼容性,而是引入了具有更清晰语义的新的替代编译指示parent
.
base
tried to do one too many things – automatically handling loading modules but also allowing establishing inheritance from classes already loaded (possibly from a file whose name wasn't based on the module name). To sort of make it work, there was some hackery that caused surprising results in some cases. Rather than break backwards compatibility, a new, replacement pragma parent
was introduced with cleaner semantics.
parent
将成为5.10.1的核心模块.
parent
will be a core module as of 5.10.1.
更新:忘记了base
处理fields
(如果使用的是fields
编译指示),而parent
则不行.
Update: forgot that base
handles fields
(if you are using the fields
pragma), which parent
doesn't do.
这篇关于Perl 5中的parent和base有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!