Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: I have a perl snippet. And I need help understanding it. Can you help answer these questions.

by davido (Cardinal)
on Nov 08, 2011 at 05:27 UTC ( [id://936664]=note: print w/replies, xml ) Need Help??


in reply to Re^2: I have a perl snippet. And I need help understanding it. Can you help answer these questions.
in thread I have a perl snippet. And I need help understanding it. Can you help answer these questions.

Correct: new() is not a built-in. I assumed that it existed in the module, and that you just didn't include that portion of the code. Otherwise, the code you posted wouldn't have made much sense. new() is the "constructor" for the object, and it has to be written by the module's author. There's nothing special about the name new() either. DBI uses connect(), and other modules use other names that make sense as constructors for their respective classes. However, unless you have a good reason, new() is usually the most predictable and sensible name to use.

One thing: The code you posted is really a bad example to learn from. It's considered a bad practice to deal with the object's internals directly from outside the object, and that's what the example code is doing. The class's author should be free to implement the object however he wants internally, and expose its internals through well-defined accessors in a way that abstracts away the details of implementation. ...that's at least my opinion about what code I saw posted. But I understand you've got the hand of cards that some previous developer handed you. Just be aware that when it comes time to actually learn how to write OO in Perl, Intermediate Perl is an excellent resource. And Modern Perl (by chromatic) will get you started with Moose (Perl's newer, more palatable object system).


Dave

  • Comment on Re^3: I have a perl snippet. And I need help understanding it. Can you help answer these questions.
  • Select or Download Code

Log In?
Username:
Password:

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

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

    No recent polls found