Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Bug in 5.8.0 fields/base pragmata?

by schwern (Scribe)
on Apr 05, 2003 at 03:22 UTC ( #248252=note: print w/replies, xml ) Need Help??

in reply to Bug in 5.8.0 fields/base pragmata?

Confirmed, this is a bug in Class::Field's implementation of 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 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, 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 *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 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 to use restricted hashes in 5.9 and wrote Hash::Util. I have some experience with the subject. ;)

Replies are listed 'Best First'.
Re: Re: Bug in 5.8.0 fields/base pragmata?
by Gnezdo (Initiate) on Jul 23, 2003 at 22:36 UTC
    Here is a test case that reliably demonstrates the problem on 5.8.0. If you move the second "use base" to before the preceeding "use fields" the test will succeed. Internally %Bar::FIELDS is getting populated with duplicate values which is causing the trouble.
    package Foo; use strict; use fields qw(Foo_field); sub new ($) { return fields::new(shift); } package Bar; use strict; use fields qw(Bar_field); use base qw(Foo); package main; use Test::More 'no_plan'; my Bar $obj = new Bar(); ok ($obj, "got instance"); ok ($obj->isa("Bar"), "it's a Bar"); ok ($obj->isa("Foo"), "it's a Foo"); ok ($obj->{Bar_field} = 2, "Can assign Bar_field"); ok ($obj->{Foo_field} = 3, "Can assign Foo_field"); is ($obj->{Bar_field}, 2, "Bar is assigned"); is ($obj->{Foo_field}, 3, "Foo is assigned");

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://248252]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-09-25 19:45 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (472 votes). Check out past polls.