Clone-Util
view release on metacpan or search on metacpan
lib/Clone/Util.pm view on Meta::CPAN
use 5.010001;
use strict;
use warnings;
use Function::Fallback::CoreOrPP qw(clone);
use Exporter qw(import);
our @EXPORT_OK = qw(clone modclone sclone);
sub modclone(&$;@) {
my $code = shift;
my $data = shift;
my $clone = clone($data);
local $_ = $clone;
$code->($clone);
if (@_ || wantarray) {
return ($clone, @_);
} else {
return $clone;
}
}
sub sclone($) {
my $data = shift;
my $ref = ref($data);
if ($ref eq 'ARRAY') {
return [@$data];
} elsif ($ref eq 'HASH') {
return {%$data};
} else {
die "Cannot shallow clone $data ($ref)";
}
}
( run in 0.388 second using v1.01-cache-2.11-cpan-1f129e94a17 )