creeble has asked for the wisdom of the Perl Monks concerning the following question:

I've been a long-time user of Class::Struct::FIELDS for data inheritance and automatic accessor creation, but I just found that it doesn't seem to work under perl 5.10:

file1:

package thing; use Class::Struct::FIELDS; struct (thing => {qw { this $ that @ }});
file 2:
package morething; use Class::Struct::FIELDS; use thing; struct (morething => [qw(thing)], { qw{ another $ yetmore @ }});
and finally:
use thing; use morething; $mt = morething->new; $mt->this('issomething');
Works great under 5.8.5, but under 5.10 I get:
Modification of a read-only value attempted at (eval 7) line 48.
Okay, I'm ready to be completely embarrassed by being told I should use something more modern for data inheritance, but I'm somewhat shocked that this could be so utterly broken between two minor (!) Perl version releases.

Replies are listed 'Best First'.
Re: Class::Struct::FIELDS broken under 5.10?
by Corion (Patriarch) on Jun 16, 2011 at 15:46 UTC

    A change from 5.8.x to 5.10.x is considered a change in major version for Perl 5. And unsurprisingly, in perl5100delta, the changes file listing the changes from 5.8.x to 5.10.0, there is mention:

    Pseudo-hashes have been removed Support for pseudo-hashes has been removed from Perl 5.9. (The "fiel +ds" pragma remains here, but uses an alternate implementation.)

    It seems that your use of fields is incompatible with the new implementation.

Re: Class::Struct::FIELDS broken under 5.10?
by toolic (Bishop) on Jun 16, 2011 at 15:55 UTC
    Someone submitted a patch for a "Modification of a read-only value attempted" bug 9 months ago. I'm not sure if it is the same issue you're having, but it's worth a look.

    It is also worth considering the possibility that Class::Struct::FIELDS is no longer supported, since this bug has not been acknowledged and all CPAN Tester tests have been failing for all perl versions 5.95 and later (and on all platforms).

      Darn. Well, does anyone have a recommendation for one of the many Class::* modules to replace Class::Struct::FIELDS? Class::Struct is great, but can't be subclassed easily. Class::Generator allows subclassing, but you must use closures for member functions. The thing I liked about Class::Struct (and ::FIELDS) is that you could combine simple member functions (defined outside the struct()) with subclassing.