{ ... sub new { my ($class, $cords) = @_; ... } ... } my $point = PointX->new({x=>3, y=>20});

By passing a hash reference as an argument to your constructor, you are creating and destroying a hash at each object creation just for passing the arguments, which wouldn't be the case if you passed in a list (built => 'with', fat => 'commas'). A lexical hash inside the constructor which takes the arguments is created and allocated once (but its keys and values are cleared when its scope is left).

This is a trivial example of just having 2 items tracked with a single hash. My current application will track around a dozen. I'd prefer not to have a dozen hashes, but I will if it's deemed to be The-Right-Thing (tm).

Check out Anno's Alter package, which is a nice alternative to "traditional" inside-out objects based on lexical hashes. It supports multiple inheritance, doesn't need refaddr, needs no fiddling with DESTROY, objects created that way are garbage-collected in the same way as all perl data types and thread safe. It implements data encapsulation in a most perlish and elegant way.

IMHO, it supersedes and obsoletes the lexical-hash-style inside-out packages. Somebody had to say it...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Inside Out Classes and the internal Hashes by shmem
in thread Inside Out Classes and the internal Hashes by KurtSchwind

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.