Today I’m fighting Mus , and I’m faced with the following problem. I create an object with many necessary attributes when creating it. However, I want to add attributes to it when the method is called. In particular, I would like to add arguments for this method as a hash attribute. I would like to do this so that subsequent calls to other methods know that an earlier method has already been called with the specified parameters.
Example, but fictional code:
package Banana;
use Moose;
has ['peel', 'edible'] => (
is => 'ro',
isa => 'Bool',
required => 1,
);
has 'color' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'grow_params' => (
is => 'ro',
isa => 'HashRef',
);
sub grow {
my ($self, $params) = @_;
$self->grow_params = $params;
}
This will not work as the following error occurs:
Unable to change non-lvalue subroutine call &Banana::grow_params
SO PerlMonks, , . . , , , ? ?