1MooseX::Attribute::ChaiUnseedrClCoonnet(r3i)buted Perl DMoocousmeeXn:t:aAttitornibute::ChainedClone(3)
2
3
4

NAME

6       MooseX::Attribute::ChainedClone - Attribute that returns a cloned
7       instance
8

VERSION

10       version 1.0.3
11

SYNOPSIS

13         package Test;
14         use Moose;
15
16         has debug => (
17             traits => [ 'ChainedClone' ],
18             is => 'rw',
19             isa => 'Bool',
20             default => 0,
21         );
22
23         sub complex_method
24         {
25             my $self = shift;
26
27             #...
28
29             print "helper message" if $self->debug;
30
31             #...
32         }
33
34         sub clone {
35             my $self = shift;
36             # custom clone code here
37             # defaults to:
38             return bless { %$self }, ref $self;
39         }
40
41
42         1;
43
44       Which allows for:
45
46           my $test = Test->new;
47           $test->debug(1)->complex_method; # debug enabled
48                                            # complex_method is called on a cloned instance
49                                            # with debug set to 1
50
51           $test->complex_method;           # debug is still disabled on $test
52
53           $test->debug(1); # returns a cloned $test instance with debug set to 1
54           $test->debug;    # returns 0
55

DESCRIPTION

57       MooseX::Attribute::ChainedClone is a Moose Trait which allows for
58       method chaining on accessors by returning a cloned instance of $self on
59       write/set operations.
60
61       If $self has a "clone" method, this method is invoked to clone the
62       instance.  This allows for easy integration with MooseX::Clone or any
63       custom made clone method. If no "clone" method is available, the new
64       instance is build using "bless { %$self }, ref $self".
65

AUTHORS

67       •   Tom Hukins <tom@eborcom.com>
68
69       •   Moritz Onken <onken@netcubed.de>
70
71       •   David McLaughlin <david@dmclaughlin.com>
72
74       This software is copyright (c) 2017 by Tom Hukins.
75
76       This is free software; you can redistribute it and/or modify it under
77       the same terms as the Perl 5 programming language system itself.
78

BUGS

80       Please report any bugs or feature requests on the bugtracker website
81       <http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Attribute-Chained>
82       or by email to bug-moosex-attribute-chained at rt.cpan.org.
83
84       When submitting a bug or request, please include a test-file or a patch
85       to an existing test-file that illustrates the bug or desired feature.
86
87
88
89perl v5.36.0                      2023-01-20MooseX::Attribute::ChainedClone(3)
Impressum