PrePAN

Sign in to PrePAN

Data::Walk::Clone deep data cloning with boundaries

Good

Synopsis

#! C:/Perl/bin/perl
use Modern::Perl;
use Moose::Util qw( with_traits );

use Data::Walk::Extracted v0.009;
use Data::Walk::Clone v0.003;

my  $dr_nisar_ahmad_wani = with_traits( 
	'Data::Walk::Extracted', 
	( 'Data::Walk::Clone',  ) 
)->new( 
	skip_clone_tests =>[  [ 'HASH', 'LowerKey2', 'ALL',   'ALL' ] ],
);
my  $donor_ref = {
	Someotherkey    => 'value',
	Parsing         =>{
		HashRef =>{
			LOGGER =>{
				run => 'INFO',
			},
		},
	},
	Helping =>[
		'Somelevel',
		{
			MyKey =>{
				MiddleKey =>{
					LowerKey1 => 'lvalue1',
					LowerKey2 => {
						BottomKey1 => 'bvalue1',
						BottomKey2 => 'bvalue2',
					},
				},
			},
		},
	],
};
my	$injaz_ref = $dr_nisar_ahmad_wani->deep_clone(
			donor_ref => $donor_ref,
	);
if(
	$injaz_ref->{Helping}->[1]->{MyKey}->{MiddleKey}->{LowerKey2} eq
	$donor_ref->{Helping}->[1]->{MyKey}->{MiddleKey}->{LowerKey2}		){
	print "The data is not cloned at the skip point\n";
}
		
if( 
	$injaz_ref->{Helping}->[1]->{MyKey}->{MiddleKey} ne
	$donor_ref->{Helping}->[1]->{MyKey}->{MiddleKey}		){
	print "The data is cloned above the skip point\n";
}
    
#######################################
#     Output of SYNOPSIS
# 01 The data is not cloned at the skip point
# 02 The data is cloned above the skip point
#######################################

Description

This Moose::Role contains methods for implementing the method deep_clone using Data::Walk::Extracted.
This method is used to deep clone a data ref. Cloning is accomplished by sending a 'donor_ref' that has data that you want copied into a different memory location. It may be that some portion of the data should maintain common memory location pointers to the original memory locations and so two ways of defining where to stop deep cloning are provided. First a level callout where deep cloning can stop at a common level. Second a matching tool where key or node type matching can be done across multiple levels or only at targeted levels.

Comments

Please sign up to post a review.