Subject: | Moose::Meta::Attribute::Native::Trait::Array -, attrib declared as 'ro', could still be 'rw'? |
I am puzzled because ...
in the SYNOPSIS block of the Perldoc of Module
Moose::Meta::Attribute::Native::Trait::Array -
e.g. see here
http://search.cpan.org/~flora/Moose-1.03/lib/Moose/Meta/Attribute/Native/Trait/Array.pm
attrib 'options' is declared as 'ro'.
it seems to me that Attributes declared as 'ro' are actually 'rw' -
because it can be written to with the 'push' method of the
Moose::Meta::Attribute::Native::Trait::Array Attribute.
otherwise add_option etc from the 'handles' => option below would not
make any sense ... it is contradictory in some way. Or am I missing
something here?
See test script below, inspired by Mouse-0.51/t/001_mouse/019-handles.t.
use strict;
use warnings;
use Test::More;
use Test::Exception;
do {
package Stuff;
use Moose;
has name => (is => 'rw');
has 'options' => (
traits => ['Array'],
is => 'ro', # <== should be 'rw',
isa => 'ArrayRef[Str]',
default => sub { [] },
handles => {
all_options => 'elements',
add_option => 'push',
map_options => 'map',
filter_options => 'grep',
find_option => 'first',
get_option => 'get',
join_options => 'join',
count_options => 'count',
has_options => 'count',
has_no_options => 'is_empty',
sorted_options => 'sort',
},
);
1;
};
can_ok(Stuff => qw(options has_options all_options add_option));
my $object2 = Stuff->new( name => "xx");
is($object2->name, "xx", "we really do have a Stuff ");
ok($object2->has_no_options, "... empty 'option' attrib");
is($object2->has_options, 0, "there are no options");
ok($object2->add_option ("x"), "WHY does this work, the 'options'
attribute is read-only");
is($object2->has_options, 1, "now there is an option");
done_testing;
Linux 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010
x86_64 GNU/Linux
This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi