1MooseX::Clone(3pm)    User Contributed Perl Documentation   MooseX::Clone(3pm)
2
3
4

NAME

6       MooseX::Clone - Fine-grained cloning support for Moose objects.
7

VERSION

9       version 0.06
10

SYNOPSIS

12           package Bar;
13           use Moose;
14
15           with qw(MooseX::Clone);
16
17           has foo => (
18               isa => "Foo",
19               traits => [qw(Clone)], # this attribute will be recursively cloned
20           );
21
22           package Foo;
23           use Moose;
24
25           # this API is used/provided by MooseX::Clone
26           sub clone {
27               my ( $self, %params ) = @_;
28
29               # ...
30           }
31
32
33           # used like this:
34
35           my $bar = Bar->new( foo => Foo->new );
36
37           my $copy = $bar->clone( foo => [ qw(Args for Foo::clone) ] );
38

DESCRIPTION

40       Out of the box Moose only provides very barebones cloning support in
41       order to maximize flexibility.
42
43       This role provides a "clone" method that makes use of the low level
44       cloning support already in Moose and adds selective deep cloning based
45       on introspection on top of that. Attributes with the "Clone" trait will
46       handle cloning of data within the object, typically delegating to the
47       attribute value's own "clone" method.
48

TRAITS

50       Clone
51           By default Moose objects are cloned like this:
52
53               bless { %$old }, ref $old;
54
55           By specifying the Clone trait for certain attributes custom
56           behavior the value's own "clone" method will be invoked.
57
58           By extending this trait you can create custom cloning for certain
59           attributes.
60
61           By creating "clone" methods for your objects (e.g. by composing
62           MooseX::Compile) you can make them interact with this trait.
63
64       NoClone
65           Specifies attributes that should be skipped entirely while cloning.
66

METHODS

68       clone %params
69           Returns a clone of the object.
70
71           All attributes which do the
72           MooseX::Clone::Meta::Attribute::Trait::Clone role will handle
73           cloning of that attribute. All other fields are plainly copied
74           over, just like in "clone_object" in Class::MOP::Class.
75
76           Attributes whose "init_arg" is in %params and who do the "Clone"
77           trait will get that argument passed to the "clone" method
78           (dereferenced). If the attribute does not self-clone then the param
79           is used normally by "clone_object" in Class::MOP::Class, that is it
80           will simply shadow the previous value, and does not have to be an
81           array or hash reference.
82

TODO

84       Refactor to work in term of a metaclass trait so that
85       "meta->clone_object" will still do the right thing.
86

THANKS

88       clkao made the food required to write this module
89

AUTHOR

91       XXXX XXX'XX (Yuval Kogman) <nothingmuch@woobling.org>
92
94       This software is copyright (c) 2008 by XXXX XXX'XX (Yuval Kogman).
95
96       This is free software; you can redistribute it and/or modify it under
97       the same terms as the Perl 5 programming language system itself.
98
99
100
101perl v5.32.1                      2021-01-27                MooseX::Clone(3pm)
Impressum