MooseX:...:Cloning(3)
π MooseX::Extended::Manual::Cloning π
okay bestie, gather round, because we're talking about MooseX::Extended::Manual::Cloning β the manual page that gives you the whole rundown on MooseX::Extended's optional attribute cloning. yes, that's the whole vibe. it's giving "overview energy" and we're obsessed. β¨
version: 0.35. that's the one, no cap.
π CLONING SUPPORT π
so here's the tea, bestie: MooseX::Extended offers optional, EXPERIMENTAL support for attribute cloning β but the way it works is lowkey different from how you usually see this done. π
the easy mode? just pass the clone => 1 argument to your attribute. that's it. it'll get cloned with Storable's dclone function every single time you read or write that attribute. and if it's a reference, it gets cloned too β which means your object is effectively immutable. iconic behavior honestly. π₯
but wait, there's more, because of course there is. if clone => 1 isn't your thing, you can also pass:
- a code reference, or
- the name of a method that you'll use to clone the object.
either way, each one receives three arguments: $self, $attribute_name, $value_to_clone. three lil guys. that's the whole contract. π«Ά
here's a full example, straight from the test suite β not me gatekeeping, it's literally right here:
package My::Class {
use MooseX::Extended types => [qw(NonEmptyStr HashRef InstanceOf)];
param name => ( isa => NonEmptyStr );
param payload => (
isa => HashRef,
clone => 1, # uses Storable::dclone
writer => 1,
);
param start_date => (
isa => InstanceOf ['DateTime'],
clone => sub ( $self, $name, $value ) {
return $value->clone;
},
);
param end_date => (
isa => InstanceOf ['DateTime'],
clone => '_clone_end_date',
);
sub _clone_end_date ( $self, $name, $value ) {
return $value->clone;
}
sub BUILD ( $self, @ ) {
if ( $self->end_date < $self->start_date ) {
croak("End date must not be before start date");
}
}
}
β οΈ Warning, bestie, listen up: this is a very useful technique, but cloning can be very expensive. π if you're having performance issues, profile your code and see if removing the safety of cloning can help. don't just rawdog it and hope, okay? profile first. π
π AUTHOR π
Curtis "Ovid" Poe <curtis.poe@gmail.com>
πΈ COPYRIGHT AND LICENSE πΈ
This software is Copyright (c) 2022 by Curtis "Ovid" Poe.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
and that's a wrap, my love π this was MooseX::Extended::Manual::Cloning, served up from perl v5.42.0, dated 2025-07-25. go forth and clone responsibly (or don't clone at all if your profiler is screaming at you). mwah! πβ¨ππ¦
π¦ where this page comes from
- fedora 43: perl-MooseX-Extended 0.35-6.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms