MooseX::Role::UpdateAttributes - Update attribute values
package Models::Person { use Moose; with 'MooseX::Role::UpdateAttributes'; has 'name' => ( is => 'ro', isa => 'Str', required => 1 ); has 'age' => ( is => 'rw', isa => 'Int', required => 1 ); __PACKAGE__->meta()->make_immutable(); } package main { my $person = Models::Person->new( { name => 'Bruce Wayne', age => 30 } ); $person->set_attributes( name => 'Wally West', age => 22, dummy => 100, ); $person->name(); # Still 'Bruce Wayne' because the name attribute is read-only $person->age(); # Is now set to 22 }
This role allow for setting the values for setting values on multiple writable accesors at once.
$instance->set_attributes( %data );
Tudor Marghidanu <tudor@marghidanu.com>
Moose
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
To install MooseX::Role::UpdateAttributes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::UpdateAttributes
CPAN shell
perl -MCPAN -e shell install MooseX::Role::UpdateAttributes
For more information on module installation, please visit the detailed CPAN module installation guide.