Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

moosex::clone::meta::attribute::trait::clone(3pm) [debian man page]

MooseX::Clone::Meta::Attribute::Trait::Clone(3pm)	User Contributed Perl Documentation	 MooseX::Clone::Meta::Attribute::Trait::Clone(3pm)

NAME
MooseX::Clone::Meta::Attribute::Trait::Clone - The Moose::Meta::Attribute trait for deeply cloning attributes. SYNOPSIS
# see MooseX::Clone has foo => ( traits => [qw(Clone)], isa => "Something", ); $object->clone; # will recursively call $object->foo->clone and set the value properly DESCRIPTION
This meta attribute trait provides a "clone_value" method, in the spirit of "get_value" and "set_value". This allows clone methods such as the one in MooseX::Clone to make use of this per-attribute cloning behavior. DERIVATION
Deriving this role for your own cloning purposes is encouraged. This will allow your fine grained cloning semantics to interact with MooseX::Clone in the RightX way. ATTRIBUTES
clone_only_objects Whether or not Data::Visitor should be used to clone arbitrary structures. Objects found in these structures will be cloned using clone_object_value. If true then non object values will be copied over in shallow cloning semantics (shared reference). Defaults to false (all reference will be cloned). clone_visitor_config A hash ref used to construct "clone_visitor". Defaults to the empty ref. This can be used to alter the cloning behavior for non object values. clone_visitor The Data::Visitor::Callback object that will be used to clone. It has an "object" handler that delegates to "clone_object_value" and sets "tied_as_objects" to true in order to deeply clone tied structures while retaining magic. Only used if "clone_only_objects" is false and the value of the attribute is not an object. METHODS
clone_value $target, $proto, %args Clones the value the attribute encapsulates from $proto into $target. clone_value_data $value, %args Does the actual cloning of the value data by delegating to a "clone" method on the object if any. If the object does not support a "clone" method an error is thrown. If the value is not an object then it will not be cloned. In the future support for deep cloning of simple refs will be added too. clone_object_value $object, %args This is the actual workhorse of "clone_value_data". clone_any_value $value, %args Uses "clone_visitor" to clone all non object values. Called from "clone_value_data" if the value is not an object and "clone_only_objects" is false. perl v5.10.1 2010-01-01 MooseX::Clone::Meta::Attribute::Trait::Clone(3pm)

Check Out this Related Man Page

Data::Clone(3pm)					User Contributed Perl Documentation					  Data::Clone(3pm)

NAME
Data::Clone - Polymorphic data cloning VERSION
This document describes Data::Clone version 0.003. SYNOPSIS
# as a function use Data::Clone; my $data = YAML::Load("foo.yml"); # complex data structure my $cloned = clone($data); # makes Foo clonable package Foo; use Data::Clone; # ... # Foo is clonable my $o = Foo->new(); my $c = clone($o); # $o is deeply copied # used for custom clone methods package Bar; use Data::Clone qw(data_clone); sub clone { my($proto) = @_; my $object = data_clone($proto); $object->do_something(); return $object; } # ... # Bar is also clonable $o = Bar->new(); $c = clone($o); # Bar::clone() is called DESCRIPTION
"Data::Clone" does data cloning, i.e. copies things recursively. This is smart so that it works with not only non-blessed references, but also with blessed references (i.e. objects). When "clone()" finds an object, it calls a "clone" method of the object if the object has a "clone", otherwise it makes a surface copy of the object. That is, this module does polymorphic data cloning. Although there are several modules on CPAN which can clone data, this module has a different cloning policy from almost all of them. See "Cloning policy" and "Comparison to other cloning modules" for details. Cloning policy A cloning policy is a rule that how a cloning routine copies data. Here is the cloning policy of "Data::Clone". Non-reference values Non-reference values are copied normally, which will drop their magics. Scalar references Scalar references including references to other types of references are not copied deeply. They are copied on surface because it is typically used to refer to something unique, namely global variables or magical variables. Array references Array references are copied deeply. The cloning policy is applied to each value recursively. Hash references Hash references are copied deeply. The cloning policy is applied to each value recursively. Glob, IO and Code references These references are not copied deeply. They are copied on surface. Blessed references (objects) Blessed references are not copied deeply by default, because objects might have external resources which "Data::Clone" could not deal with. They will be copied deeply only if "Data::Clone" knows they are clonable, i.e. they have a "clone" method. If you want to make an object clonable, you can use the "clone()" function as a method: package Your::Class; use Data::Clone; # ... my $your_class = Your::Class->new(); my $c = clone($your_object); # $your_object->clone() will be called Or you can import "data_clone()" function to define your custom clone method: package Your::Class; use Data::Clone qw(data_clone); sub clone { my($proto) = @_; my $object = data_clone($proto); # anything what you want return $object; } Of course, you can use "Clone::clone()", "Storable::dclone()", and/or anything you want as an implementation of "clone" methods. Comparison to other cloning modules There are modules which does data cloning. "Storable" is a standard module which can clone data with "dclone()". It has a different cloning policy from "Data::Clone". By default it tries to make a deep copy of all the data including blessed references, but you can change its behaviour with specific hook methods. "Clone" is a well-known cloning module, but it does not polymorphic cloning. This makes a deep copy of data regardless of its types. Moreover, there is no way to change its behaviour, so this is useful only for data which link to no external resources. "Data::Clone" makes a deep copy of data only if it knows that the data are clonable. You can change its behaviour simply by defining "clone" methods. It also exceeds "Storable" and "Clone" in performance. INTERFACE
Exported functions clone(Scalar) Returns a copy of Scalar. Exportable functions data_clone(Salar) Returns a copy of Scalar. The same as "clone()". Provided for custom clone methods. is_cloning() Returns true inside the "clone()" function, false otherwise. DEPENDENCIES
Perl 5.8.1 or later, and a C compiler. BUGS
No bugs have been reported. Please report any bugs or feature requests to the author. SEE ALSO
Storable Clone AUTHOR
Goro Fuji (gfx) <gfuji(at)cpan.org> LICENSE AND COPYRIGHT
Copyright (c) 2010, Goro Fuji (gfx). All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-01-15 Data::Clone(3pm)
Man Page