in reply to Private Attributes in Moose

Since you are telling Moose to create two functions (a reader and a writer) with the same name, it's no wonder you are having problems!
has priv_attr => ( accessor => '_priv_attr', isa => 'Str', );
has _priv_attr => ( init_arg => 'priv_attr', is => 'rw', isa => 'Str', );
has _priv_attr => ( is => 'rw', isa => 'Str', );
has _priv_attr => ( init_arg => undef, is => 'rw', isa => 'Str', );
1: Can be initialised using ->new( priv_attr => ... ) 2: Can be initialised using ->new( priv_attr => ... ) 3: Can be initialised using ->new( _priv_attr => ... ) 4: Cannot be initialised from outside the class.

Replies are listed 'Best First'.
Re^2: Private Attributes in Moose
by musiKk (Initiate) on Jul 23, 2011 at 16:10 UTC

    That's it. I wasn't aware of accessor. It would've been nice if Moose had used accessor internally after seeing that both reader and writer have the same name but I'm sure that's debatable. Thank you.

      It's actually Class::MOP (not Moose) that uses those, but yeah, I don't see the harm in adding that functionality.