tachyon's
post above covers the bases. Here are a few other tidbits about Object Oriented Perl as explained by
TheDamian.
A class is a package. You must have seen packages in Perl before, and you probably understand that they give you a nice, fresh, separate name space for some group of data and functionality. Well, that's fundamentally all an OO class is. The main difference is that classes do not / should not Export any variables into the namespace from which it is called. It gives you the methods to do what you need, without inviting you into it's house for tea.
A method is a subroutine. Make a sub in that package/class file, and voila! You have a method that operates on the data in your class! These methods are often the only things that are allowed to play with the data in your object.
An object is a blessed referent. Here's the magic. The Perl function
bless() simply associates your class' data structure with that specific class. If you dump your class object with
Data::Dumper, you'll see the class name tacked on the end. This is how Perl knows that your data belongs to that class, and it bumps up your data structure's reference count so that it sticks around.
I'm a HUGE fan of OO programming. If you have the time and the motivation, I highly recommend that you grab this book:
Object Oriented Perl. It's made my job so much easier and more fun! Seriously!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.