in reply to Migrate your perl project to Moose
and translate to Moose code like this:sub name { my $self = shift; my $new_value = shift; $self->{_name} = $new_value if defined $new_value; return $self->{_name}; }
So, first identify attributes of the class which store data and convert them to Moose using the "has" declaration. You will be left with methods in the original code that perform some action on the attributes and you can leave them mostly untouched except that you want to make sure you don't access the underlying blessed hash of attributes directly, so you want to change (in my example) all occurrences of $self->{_name} to $self->name throughout the code.has 'name' => ( is => 'rw', isa => 'Str', );
|
|---|