You can look at Moose, which makes OO writing pretty easy.

A class is declared as:

package Class::Name;
a package is a symbol table namespace, in which symbols are stored. Every class has it's own package which it lives in.

Constructors are anything which calls bless, you should read perltoot to get a handle on that, but if you want to ignore that Moose will provide a default constructor named new for you.

Every class gets DESTROY called right before it's garbage collected. You can hook to that. C<Moose> let's you specify sub DEMOLISH which does not have to call the super class's destructors.

Inheritence is controlled with the special variable @ISA in every package, which contains a list of base classes. YOu can use the extends keyword in Moose to clean that up a bit.

Accessors are autogenerated for you when you use attributes, like:

has name => ( is => "rw", # what accessor to generate, can also be wo or ro );

I don't know what you mean by contexts - that's a very general term.

-nuffin
zz zZ Z Z #!perl

In reply to Re: How best to learn OO Perl? by nothingmuch
in thread How best to learn OO Perl? by rose

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.