MooseX...edClone(3pm)
π NAME π
MooseX::Attribute::ChainedClone β the Moose attribute trait that hands you back a cloned instance so you can chain your accessors, bestie. It's a 3pm Perl manual page, and yes it's exactly as iconic as it sounds.
β¨ VERSION β¨
version 1.0.3 β freshly stamped, no cap πΈ
π SYNOPSIS π
okay so picture this: you want $test->debug(1)->complex_method to just work. Here's the setup:
package Test;
use Moose;
has debug => (
traits => [ 'ChainedClone' ],
is => 'rw',
isa => 'Bool',
default => 0,
);
sub complex_method
{
my $self = shift;
#...
print "helper message" if $self->debug;
#...
}
sub clone {
my $self = shift;
# custom clone code here
# defaults to:
return bless { %$self }, ref $self;
}
1;
Which allows for:
my $test = Test->new;
$test->debug(1)->complex_method; # debug enabled
# complex_method is called on a cloned instance
# with debug set to 1
$test->complex_method; # debug is still disabled on $test
$test->debug(1); # returns a cloned $test instance with debug set to 1
$test->debug; # returns 0
likeβ¦ the way that works is genuinely so satisfying, no notes π
π¦ DESCRIPTION π¦
MooseX::Attribute::ChainedClone is a Moose Trait, and what it does is let you chain methods on accessors by returning a cloned instance of $self whenever you do a write/set operation. periodt.
So if $self happens to have a clone method, that's the one that gets invoked to clone the instance β which means it plays so nicely with MooseX::Clone, or honestly any custom clone method you felt like making. And if there's no clone method to be found? No stress, the new instance gets built with bless { %$self }, ref $self. iconic behavior honestly π«Ά
π AUTHORS π
- Tom Hukins
<tom@eborcom.com> - Moritz Onken
<onken@netcubed.de> - David McLaughlin
<david@dmclaughlin.com>
three absolute legends fr fr β¨
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2017 by Tom Hukins.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π BUGS π
Please report any bugs or feature requests on the bugtracker website <http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Attribute-Chained> or by email to bug-moosex-attribute-chained at rt.cpan.org.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
bestie please actually include the test file π a bug report with no repro is giving nothing, and we can't fix a vibe we can't see. give us the patch and we'll give you the fix. π
and that's the whole page, main character energy from start to finish π This lil manual moment comes to you from perl v5.34.0, dated 2022-06-15 β mwah, go chain some accessors ππ¦π
π¦ where this page comes from
- debian bookworm: libmoosex-attribute-chained-perl 1.0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-attribute-chained-perl 1.0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-attribute-chained-perl 1.0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-attribute-chained-perl 1.0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-attribute-chained-perl 1.0.3-2 Β· 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