+ - perl based getter dies if @_ > 1 (XSAccessor already did)
- add Role::Tiny::With for use in classes
- automatically generate constructors in subclasses when required so that
subclasses with a BUILD method but no attributes get it honoured
use B 'perlstring';
BEGIN {
our $CAN_HAZ_XS =
+ !$ENV{MOO_XS_DISABLE}
+ &&
_maybe_load_module('Class::XSAccessor')
&&
(Class::XSAccessor->VERSION > 1.06)
$self->{captures} = {};
$methods{$reader} =
quote_sub "${into}::${reader}"
- => $self->_generate_get($name, $spec)
+ => ' die "'.$reader.' is a read-only accessor" if @_ > 1;'."\n"
+ .$self->_generate_get($name, $spec)
=> delete $self->{captures}
;
}
$foo->set_one('rofl');
is( $foo->get_one, 'rofl', 'writer works' );
+ok( !eval { $foo->get_one('blah'); 1 }, 'reader dies on write' );
+
is( $bar->TWO, '...', 'accessor works for reading' );
$bar->TWO('!!!');
is( $bar->TWO, '!!!', 'accessor works for writing' );
my $foo = Foo->new(one => 1);
is($foo->one, 1, 'ro reads');
-$foo->one(-3) unless $Method::Generate::Accessor::CAN_HAZ_XS;
+ok(!eval { $foo->one(-3); 1 }, 'ro dies on write attempt');
is($foo->one, 1, 'ro does not write');
is($foo->two, undef, 'rw reads');