What is the difference between parent and base in Perl 5?

后端 未结 2 1815
天涯浪人
天涯浪人 2020-12-13 00:11

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 missin

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 00:43

    Armed with the extra bit of information from ysth, I was able to see the differences in the docs:

    The base pragma does the following things:

    • adds the named package to @ISA
    • loads the module with the same name as the named package using require (unless it detects that the package has already been loaded)
    • won't fail if a module with the same name as the package doesn't exist
    • dies if there are no symbols in the named package
    • if $VERSION does not exist in named package, base sets it to "-1, set by base.pm"
    • initializes the fields of the named package if they exist
    • does not call the import function of the named package

    The parent pragma does the following things:

    • adds the named package to @ISA
    • loads the module with the same name as the named package using require
    • accepts an option that tells it not to die if a module with the same name as the package doesn't exist

提交回复
热议问题