Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Understanding a OOp code

by GrandFather (Saint)
on Sep 26, 2016 at 08:58 UTC ( [id://1172614]=note: print w/replies, xml ) Need Help??


in reply to Understanding a OOp code

$hash is an object. $hash->LicenseData(); calls the "method" LicenseData on the hash object. Without bothering with details, that means a sub named LicenseData is called and passed $hash as the first parameter. The LicenseData sub uses the contents of $hash to do some work.

$hash probably isn't a very good name. If the code were written:

sub LicenseData{ my ($licCode) = @_; my $licObj = LIC_INFO($licCode); return $licObj->LicenseData(); }

it may be a little clearer.

Premature optimization is the root of all job security

Replies are listed 'Best First'.
Re^2: Understanding a OOp code
by sachinz2 (Acolyte) on Sep 26, 2016 at 09:23 UTC
    hi

    Thanks for so quick a reply,

    but, please, I am still not able to get it, I get some data with 'my $licObj = LIC_INFO($licCode);'

    but , I do not understand the objective(logic) behind calling the same sub-routine with '$licObj->LicenseData();'

    'sub LicenseData' is the sub-routine where "my licObj is created"

      Hi sachinz2,

      the objective(logic) behind calling the same sub-routine

      It's possible likely there are two subs with the name LicenseData in different packages (classes). Inside the sub, you could try doing print __PACKAGE__, " / ", ref($hash), "\n";, that will print the current package and the package of $hash (more specifically, the package that $hash is blessed into, or in OO terminology the object's class).

      Otherwise, if there's only one sub LicenseData, then this would indeed be a recursive call, and the next call to LicenseData would receive in its $lic parameter the $hash value of the caller. How the recursion ends depends on what LIC_INFO is doing.

      Update: Actually, what I wrote above about there being two (or more) sub LicenseDatas is much more likely, since I don't see a clean way for the recursion to end if there's only one sub LicenseData.

      Hope this helps,
      -- Hauke D

        Hi

        Thanks Friends

        Yes @Hauke there were 2 sub-routines.

      $licObj->LicenseData(); doesn't call the same sub. It is another example of unfortunate naming in the code. There is an element of truth in:

      There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton

      Naming things well is hard. However the big item here is that you aren't up to speed with what OO is about. The key is that $licObj is an object and methods (LicenceData() in this case) do things with the object. Maybe Not quite an OO tutorial will help make it a little clearer. A huge amount has been written about OO, but until the "Ah ha" moment comes it doesn't make much sense and even then it's likely not obvious where the benefit is. Used well it does make sense and there is a benefit.

      Premature optimization is the root of all job security

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found