It appears that several of us (you, Juerd, and I) have arrived at similar solutions to similar problems. It seems to me that Attribute::Property is the way to go, but I'll have to play with it more. I can't immediately tell whether it solves the "what if you change the implementation" challenge. I'm pretty sure your method does not.

My intent was to address the changing-implementation issue. I am pointing out that, initially, you can use an ordinary scalar (not even tied!) if that is how your API "should" work. Later, if the implementation changes (e.g., the member needs to be stored in and retrieved from a database), you can tie it within your module, and the API doesn't change. It's a significant point that I am not advocating tie-ing every member. Only those that need to be tied.

For validation, I think that having a set method that indicates success can be preferable to relying on error generation, depending on how reasonable you think it is for the programmer to know whether he's trying to set an illegal value. It's the difference between

$foo->setval($val) or $foo->setval($alternative); # and something like eval { $foo->val = $val } $@ and $foo->val = $alternative;
Something to consider.

We're not really tightening our belts, it just feels that way because we're getting fatter.

In reply to Re^2: Encapsulation without methods by Roy Johnson
in thread Encapsulation without methods by Roy Johnson

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.