MooseX...edClone(3pm)

πŸ“¦
version 1.0.3 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 ✨


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