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

It seems that the new pragma is called parent , which does roughly the same thing as base . What does parent do to guarantee a new (non-core) module? Am I missing something?

+43
perl subclass pragma
May 18 '09 at 6:36 a.m.
source share
2 answers

base tried to do too many things, automatically processing the load modules, and also allowing you to set the inheritance of already loaded classes (possibly from a file whose name was not based on the name of the module). To make it work, in some cases, hacking occurred that caused unexpected results. Instead of undoing backward compatibility, a new, pragma of replacing parent with cleaner semantics has appeared.

parent will be the main module as of 5.10.1.

Update: I forgot that base handles fields (if you use the fields pragma), which parent does not.

+47
May 18 '09 at 7:26
source share

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

base pragma does the following:

  • Adds a named package to @ISA
  • loads a module with the same name as the named package using require (if it does not detect that the package is already loaded)
  • will not work if a module with the same name as the package does not exist
  • dies if there are no characters in the named package
  • If $VERSION does not exist in the named package, the base sets it to "-1, set by base.pm"
  • initializes fields named package if they exist
  • does not call the named package import function

parent pragma does the following:

  • Adds a named package to @ISA
  • loads a module with the same name as the named package using require
  • takes a parameter that tells it that it does not die if a module with the same name as the package does not exist
+34
May 18 '09 at 13:43
source share



All Articles