Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Method of child module called by parent

by sundialsvc4 (Abbot)
on Dec 28, 2014 at 18:08 UTC ( [id://1111579]=note: print w/replies, xml ) Need Help??


in reply to Method of child module called by parent

Yes, you definitely have “the OOP idea” upside-down and backwards.   :-)   When you “call a method for an object,” you should not have to care exactly which method(s) ultimately get called.   Perl will search for the method, at runtime, by walking-up the inheritance chain from child to parent, invoking (only) the first method that it finds.   If a method in a child-class “overrides” an identically-named method in the parent, the parent method will never be directly called by Perl, but the child method can do so by means of ::SUPER, which will cause Perl to search again for another method to call, starting its search with the superclass (use base) of the child.   (Therefore, theoretically, the child does not have to be concerned as to exactly which “method of a superclass” Perl will find, simply relying upon Perl to find it at runtime.)

Modules which implement descendent classes will use the modules which define their immediate parent.   It should (almost) never be necessary for a parent-module to use any modules which define descendent classes.   If you find yourself doing that, “something’s wrong.”   (Common-code that needs to be shared by several modules, regardless of their class relationship, should probably be spun-off into a third module, for instance.)

One thing that sometimes catches people off-guard about Perl is the extent to which it relies upon at-runtime resolution of things, and how little it relies upon (or provides ...) compile-time specification of things.   Many programming languages are designed such that “incorrect” method-calls can be detected at compile time, through the use of strong-typing and so forth.   Perl simply does not have these things.   This gives it a tremendous amount of flexibility, but it does change the nature of compile-time declarations (e.g. use) in a way that you might initially find to be surprising.   You can specify any variable, and any method-name, in a $varname->methodname construct, and no compile-time error or warning will be generated.   You might be accustomed to different language behavior.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found