MooseX::Clone(3pm)
β¨ MooseX::Clone β¨
okay bestie, so this is MooseX::Clone, a page from the User Contributed Perl Documentation section of the manual, and it's literally about fine-grained cloning support for Moose objects π yes we're making copies, yes they're good copies, no cap.
π VERSION π
version 0.06
πΈ SYNOPSIS πΈ
package Bar;
use Moose;
with qw(MooseX::Clone);
has foo => (
isa => "Foo",
traits => [qw(Clone)], # this attribute will be recursively cloned
);
package Foo;
use Moose;
# this API is used/provided by MooseX::Clone
sub clone {
my ( $self, %params ) = @_;
# ...
}
# used like this:
my $bar = Bar->new( foo => Foo->new );
my $copy = $bar->clone( foo => [ qw(Args for Foo::clone) ] );
π¦ DESCRIPTION π¦
so like, out of the box Moose only gives you very barebones cloning support, and it does that on purpose β to maximize flexibility. it's giving minimalist. it's giving "we trust you".
this role provides a clone method that takes all that low level cloning support already chilling in Moose, and adds selective deep cloning based on introspection on top of it. the way that works is: attributes with the Clone trait handle cloning of data within the object, typically delegating to the attribute value's own clone method. obsessed honestly π
π TRAITS π
Clone
by default, Moose objects are cloned like this:
bless { %$old }, ref $old;
by specifying the Clone trait for certain attributes, custom behavior kicks in and the value's own clone method will be invoked.
by extending this trait you can create custom cloning for certain attributes. yes, you. go off.
by creating clone methods for your objects (e.g. by composing MooseX::Compile) you can make them interact with this trait π
NoClone
specifies attributes that should be skipped entirely while cloning. not invited to the copy party. not on the list. bye π
π METHODS π
clone %paramsβ returns a clone of the object.
all attributes which do the MooseX::Clone::Meta::Attribute::Trait::Clone role will handle cloning of that attribute. all other fields are plainly copied over, just like in clone_object in Class::MOP::Class.
attributes whose init_arg is in %params and who do the Clone trait will get that argument passed to the clone method (dereferenced). if the attribute does not self-clone then the param is used normally by clone_object in Class::MOP::Class, that is it will simply shadow the previous value, and does not have to be an array or hash reference. periodt.
π§ TODO π§
refactor to work in term of a metaclass trait so that meta->clone_object will still do the right thing. it's on the vision board bestie π
π THANKS π
clkao made the food required to write this module π«Ά iconic behavior, truly the main character of snack provision.
π AUTHOR π
XXXX XXX'XX (Yuval Kogman) <nothingmuch@woobling.org>
β COPYRIGHT AND LICENSE β
this software is copyright (c) 2008 by XXXX XXX'XX (Yuval Kogman).
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page, no notes π this was rendered with perl v5.34.0 and dated 2022-06-15 β ty for reading bestie, go clone something responsibly πΈπ β¨
π¦ where this page comes from
- debian bookworm: libmoosex-clone-perl 0.06-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-clone-perl 0.06-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-clone-perl 0.06-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-clone-perl 0.06-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-clone-perl 0.06-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms