MooX::Role::CloneSet::BuildArgs - create updated copies of truly immutable objects
package Someone; use Moo; with 'MooX::Role::CloneSet::BuildArgs'; 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::BuildArgs is a role very similar to
MooX::Role::CloneSet; the only difference is that its
cset() method does not try to obtain the current values of the object's attributes, but uses the ones the object was constructed with (using
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 object's attributes by using the
MooX::BuildArgs; thus, it really depends on the fact that none of the attributes has had its value changed since the object was constructed.
Copyright (C) 2016 Peter Pentchev <email@example.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Peter Pentchev <firstname.lastname@example.org>