NAME

Clone::Util - Utilities related to cloning

VERSION

This document describes version 0.03 of Clone::Util (from Perl distribution Clone-Util), released on 2016-03-10.

SYNOPSIS

 use Clone::Util qw(modclone sclone);

 my $row = {name=>'ujang', gender=>'m', nationality=>'id'};
 my $table = [
     $row,
     modclone { $_->{name} = 'budi' } $row,
     modclone { $_->{name} = 'asep' } $row,
     modclone { $_->{name} = 'rini'; $_->{gender} = 'f' } $row,
 ];

 my $shallow_clone = sclone($data);

FUNCTIONS

None of the functions are exported by default, but they are exportable.

clone($data) => $cloned

This is just re-exported Function::Fallback::CoreOrPP's clone().

modclone(\&code, $data) => $clone

Clone $data and then run code. Code will be given the clone of data. For convenience, $_ will also be localized and set to the clone of data. So you can access the clone using $_ in addition to $_[0].

sclone($data) => $clone

Shallow-clone $data, which must be an arrayref or a hashref. Shallow cloning means only copying the first level of data.

 my $array = [0,1,2,[3]];
 my $clone = sclone $array; # => [0,1,2,[3]], but [3] is still the same reference

 $clone->[3][0] = "three"; # $clone as well as $array become [0,1,2,["three"]]

 $clone->[0] = "zero"; # $clone becomes ["zero",1,...] but $array still [0,1,...]

You can perform shallow copying trivially yourself using:

 my $cloned_array = [@$array];
 my $cloned_hash  = {%$hash};

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Clone-Util.

SOURCE

Source repository is at https://github.com/perlancar/perl-Clone-Util.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Clone-Util

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.

SEE ALSO

Function::Fallback::CoreOrPP

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.