I'm using the fields and base pragmata in 5.8.0 for some OO stuff I'm working on. I find the combination pretty elegant, and appreciate them very much.
However, I've encountered a small problem (that vexed me quite a bit until I figured out where the issue was). Specifically, if all of the fields in a super-class are private (i.e., their names start with underscores), then sub-classes fail to respect them when inheriting. The result is that new fields in the sub-class write themselves into the same pseudo-hash slots as the fields of the super class. If there is even one non-private field in the super-class, then the sub-class fields make room for all of the super-class fields (even the private ones).
To be more specific, if the superclass Foo starts like this:
use fields qw(_foo);
and a subclass Bar looks like this:
use base 'Foo';
use fields qw(_bar _baz);
Then if you set the _bar field for a Bar instance, it clobbers whatever was in the _foo field. But if Foo was defined as this instead:
use fields qw(unused _foo);
Then Bar respects Foo's fields (even the private ones).
I've put up a page with a script demonstrating the problem, and another script with the trivial fix. Output of each script is at the bottom, after __END__. You can also see the output of perl -V.
Is this a known problem? Is there a patch already available? If not, to whose attention should I bring it? It's not a big deal to work around ("unused" field, anyone?), but it seems to me that base.pm and fields.pm probably be fixed.