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

Modules inheritance

by Arsenii Gorkin (Novice)
on May 26, 2016 at 21:06 UTC ( [id://1164228]=perlquestion: print w/replies, xml ) Need Help??

Arsenii Gorkin has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I am working on a complex software and have a lot of modules here. I heard about inheritance in Perl but have never used it on practice. I have a few modules. Let's call them A.pm, A::1.pm, A::2.pm and A::3.pm.

A.pm calls from inside module A::1, A::1 calls A::2 A::3 calls A (parent) and A::1

What is the best practice to handle this problem?

The questions are:

1) Do I have to call all the modules I need from inside every module, or daughter modules automatically inherit functions from parent A.pm?

2) What to do with daughter modules which call their "sisters"? Like: does A::3 must call A::1?

thanks!

Regards

Arsenii.

Replies are listed 'Best First'.
Re: Modules inheritance
by GrandFather (Saint) on May 26, 2016 at 21:28 UTC

    As a general thing I wouldn't bother answering a question that is a blob of text with no formatting, so count yourself lucky! If you can't be bothered to make your question readable why should I bother to answer it?

    Modules don't "inherit" from other modules, they use other modules. Inheritance is an object oriented related thing. Modules often however provide class implementations which do inherit from other classes.

    For module/package details see perlmod.

    Premature optimization is the root of all job security

      Sorry for formatting. This is my first post here and I am not accustomed for an old-fashion formatting with <> tags)) But I promise - I will learn it and further will be better with my questions. Again - sorry.

      Regarding the question - of course - classes. I need to call methods from one module in the other one (in the kind of similar sequence I asked in the question). And I do not really know how to get it. I have a lot of errors in the code due to using "Use A::n" and "use A" etc and so on in modules that use (as a result) each other across the code. I do not know - is it a bad practice or what I do wrong?

      Say: I have A that calls A::1 and A::2 and A::2 calls A as well and A::3, and A::3 calls all of those. What to better do here you think?

      Thanks!

      And again - sorry for formating.

        That sort of "circular reference" is a fairly common issue. Often breaking circularity involves pulling out some common code B that is used by both A and A::2.

        You may get better answers if you can show us a small sample of your code showing the issues.

        Probably it's a typo, but "Use A::n" is not valid Perl - Perl is case sensitive; use is lower case.

        Premature optimization is the root of all job security
Re: Modules inheritance
by stevieb (Canon) on May 26, 2016 at 21:44 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found