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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

TRAITS

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

METHODS

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

TODO

81       Refactor to work in term of a metaclass trait so that
82       "meta->clone_object" will still do the right thing.
83

THANKS

85       clkao made the food required to write this module
86

VERSION CONTROL

88       <http://code2.0beta.co.uk/moose/svn/>. Ask on #moose for commit bits.
89

AUTHOR

91       Yuval Kogman <nothingmuch@woobling.org>
92
94           Copyright (c) 2008 Yuval Kogman. All rights reserved
95           This program is free software; you can redistribute
96           it and/or modify it under the same terms as Perl itself.
97
98
99
100perl v5.12.1                      2010-01-13                  MooseX::Clone(3)
Impressum