Data-Clone

 view release on metacpan or  search on metacpan

lib/Data/Clone.xs  view on Meta::CPAN


    //MY_CXT.caller_cv = old_cv;

    finish:
    cloned = newRV_inc(proto);

    if(SvOBJECT(sv)){
        sv_bless(cloned, SvSTASH(sv));
    }

    return SvWEAKREF(cloning) ? sv_rvweaken(cloned) : cloned;
}

/* as SV* sv_clone(SV* sv) */
SV*
Data_Clone_sv_clone(pTHX_ SV* const sv) {
    SV* VOL retval = NULL;
    CV* VOL old_cv;
    dMY_CXT;
    dXCPT;

t/04_tree.t  view on Meta::CPAN

#!perl -w

use strict;
use warnings FATAL => 'all';

use Test::More;

use Data::Clone;

use Scalar::Util qw(isweak weaken);
use Data::Dumper;
$Data::Dumper::Indent   = 0;
$Data::Dumper::Sortkeys = 1;

# hash tree

my $parent = {};
my $child  = {};

$child->{parent} = $parent;
$parent->{child} = $child;

weaken $child->{parent};

my $cloned = clone($child);
is Dumper($cloned), Dumper({ parent => undef }), 'tree structure (child)';

$cloned = clone($parent);
is Dumper($cloned), Dumper($parent), 'tree structure (parent)';

cmp_ok $cloned, '==', $cloned->{child}{parent}, 'as circular refs';
ok isweak($cloned->{child}{parent}), 'correctly weaken';

# array tree

$parent = ['is_parent'];
$child  = ['is_child'];

push @{$child},  $parent;
push @{$parent}, $child;

weaken $child->[1];

$cloned = clone($child);
is Dumper($cloned), Dumper(['is_child', undef]), 'array tree (child)';

$cloned = clone($parent);
is Dumper($cloned), Dumper($parent), 'array tree (parent)';

cmp_ok $cloned, '==', $cloned->[1][1], 'as sircular refs';
ok isweak($cloned->[1][1]), 'correctly weaken';

done_testing;

t/05_super.t  view on Meta::CPAN

#!perl -w

use strict;
use warnings FATAL => 'all';

use Test::More;

use Data::Clone;

use Scalar::Util qw(isweak weaken);
use Data::Dumper;
$Data::Dumper::Indent   = 0;
$Data::Dumper::Sortkeys = 1;

my $c_clone_called;
{
    package A;
    use Data::Clone; # make clonable

    sub new {



( run in 0.570 second using v1.01-cache-2.11-cpan-65fba6d93b7 )