MooX::Role::CloneSet - create updated copies of immutable objects
package Someone; use Moo; with 'MooX::Role::CloneSet'; has name => ( is => 'ro', ); has race => ( is => 'ro', ); package main; my $first = Someone->new(name => 'Drizzt', race => 'drow'); my $hybrid = $first->cset(race => 'dwarf'); my $final = $weird->cset(name => 'Catti-brie', race => 'human');
MooX::Role::CloneSet is a role for immutable objects, providing an easy way to create a new object with some modified properties. It provides the cset() method that creates a new object with the specified changes, shallowly copying all the rest of the original object's properties.
MooX::Role::CloneSet
cset()
cset(field => value, ...)
Shallowly clone the object, making the specified changes to its attributes.
Note that this method obtains the names and values of the current attributes by dereferencing the object as a hash reference; since Moo does not provide metaclasses by default, it cannot really get to them in any other way. This will not work for parameters that declare an init_arg; see MooX::Role::CloneSet::BuildArgs for an alternative if using truly immutable objects.
init_arg
MooX::Role::CloneSet::BuildArgs
Copyright (C) 2016 Peter Pentchev <roam@ringlet.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Peter Pentchev <roam@ringlet.net>
To install MooX::Role::CloneSet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::Role::CloneSet
CPAN shell
perl -MCPAN -e shell install MooX::Role::CloneSet
For more information on module installation, please visit the detailed CPAN module installation guide.