Confirmed, this is a bug in Class::Field's implementation of fields.pm. 5.8.0's version does it right. I'll look into it, but don't expect anything soon as I've got my hands full working on stuff for 5.8.1.

I will most definately agree that fields.pm is a clumsy interface and would discourage its use in new code. Consider using something a bit more sophisticated. Class::Accessor, Class::Struct, Class::Class, Class::Generate... or whatever the state of the art for class generation and privacy is these days. I could also recommend a few simple tricks.

As for it being deprecated, or going to be thrown away, or in risk of having backwards compatibility problems in future versions of Perl, this is not true. Pseudo-hashes are going away, fields.pm is not. It will continue to work using restricted hashes. As long as you're using fields::new() and treating the resulting object exclusively as a hash you are safe.

Certain bits of fields.pm *are* going away. Anything that obviously exposes the underlying psuedo-hash is gone. That means fields::phash() and any time you assume your object is an array ref. %FIELDS will still be around, but don't trust that either.

On the flip side, using Hash::Util and lock_keys() directly means your code is tied to 5.8.0 and up. If you use fields.pm you can at least be backwards compatible. Hash::Util was not intended to be used directly in programs, it was thrown into 5.8.0 to have *some* user interface to restricted hashes upon which someone could write another more user friendly module around.

If you want to see how this all plays out, try a copy of bleadperl. All of the above has already happened. The current version of Class::Fields also already takes restricted hashes into account.

You can consider this semi-authoritative. I wrote Class::Fields, fixed and then killed pseudo-hashes, ported fields.pm to use restricted hashes in 5.9 and wrote Hash::Util. I have some experience with the subject. ;)


In reply to Re: Bug in 5.8.0 fields/base pragmata? by schwern
in thread Bug in 5.8.0 fields/base pragmata? by talkasab

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.