Subject: | Different behaviour with read-only accessors |
Class::Accessor::Fast::XS does not behave like Class::Accessor::Fast if
a ro accessor is defined, and the hash key does not exist. In this case
the module croaks with "couldn't store value in hash". See the attached
sample script.
I think this should be either corrected (don't croak, just return undef
in the XS function) or at least documented (currently the docs say that
the two modules behave the same).
Regards,
Slaven
Subject: | acc.pl |
#!/usr/bin/perl
use strict;
use warnings;
{
package Slow;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_ro_accessors(qw(foo));
sub new { bless {}, shift }
}
{
package Fast;
use base 'Class::Accessor::Fast::XS';
__PACKAGE__->mk_ro_accessors(qw(foo));
sub new { bless {}, shift }
}
warn Slow->new->foo;
warn Fast->new->foo;
__END__
Output is:
Use of uninitialized value in warn at /tmp/acc.pl line 20.
Warning: something's wrong at /tmp/acc.pl line 20.
couldn't store value in hash at /tmp/acc.pl line 21.
(script terminates here)