Clone-Choose-0.008/0000755000175000017500000000000013174573774013343 5ustar stefanstefanClone-Choose-0.008/MANIFEST0000644000175000017500000000150513174573774014475 0ustar stefanstefanChanges lib/Clone/Choose.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP README.md t/02-load-with-clone.t t/03-load-with-storable.t t/04-load-with-clone-pp.t t/Auto/00-load.t t/Auto/01-simple.t t/Auto/05-scalar.t t/Auto/06-array.t t/Auto/07-hash.t t/Clone/00-load.t t/Clone/01-simple.t t/Clone/05-scalar.t t/Clone/06-array.t t/Clone/07-hash.t t/ClonePP/00-load.t t/ClonePP/01-simple.t t/ClonePP/05-scalar.t t/ClonePP/06-array.t t/ClonePP/07-hash.t t/inline/00-load.t t/inline/01-simple.t t/inline/05-scalar.t t/inline/06-array.t t/inline/07-hash.t t/Storable/00-load.t t/Storable/01-simple.t t/Storable/05-scalar.t t/Storable/06-array.t t/Storable/07-hash.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Clone-Choose-0.008/MANIFEST.SKIP0000644000175000017500000000051013174366070015222 0ustar stefanstefan\B\.svn\b \B\.git\b \.gitignore$ .travis.yml \.[Bb][Aa][Kk]$ \.orig$ \.old$ \.tdy$ \.tmp$ \..*swp ^Makefile$ ^Build$ ^Build\.bat$ \.Inline/.* _Inline/.* \.bak$ \.tar$ \.tgz$ \.tar\.gz$ ^mess/ ^tmp/ ^testdata/ ^blib/ ^sandbox/ ^pm_to_blib$ ^_build/.* ~$ .*\.planner ^\..* Clone-Choose-.* \bxt Sandbox ^MYMETA\.json$ ^MYMETA\..*$ Clone-Choose-0.008/META.yml0000644000175000017500000000156313174573774014621 0ustar stefanstefan--- abstract: 'Choose appropriate clone utility' author: - 'Jens Rehsack ' - 'Stefan Hermes ' build_requires: Test::More: '0.9' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Clone-Choose no_index: directory: - t - inc recommends: Module::Runtime: '0' requires: Storable: '0' perl: v5.8.1 resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Clone-Choose homepage: https://metacpan.org/release/Clone-Choose license: http://dev.perl.org/licenses/ repository: https://github.com:perl5-utils/Clone-Choose.git version: '0.008' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Clone-Choose-0.008/Changes0000644000175000017500000000215713174573631014633 0ustar stefanstefanRevision history for Clone-Choose 0.008 2017-10-27 - Prove whether all prerequisites are available for a particular backend before the test starts. 0.007 2017-10-27 - Fix simple test to not fail if preselected backend is not found. 0.006 2017-10-26 - Use inline test templates to ńot fail if . is not in @INC. - Do more tests with the different backends. 0.005 2017-10-24 - avoid distributing Sandbox - fixes GH issue#2 reported by Slaven Rezić 0.004 2017-10-24 - Added get_backends() function which returns a list of currently supported backends. - Extended testing for the different clone() providing backends. - Introduce environment variable CLONE_CHOOSE_PREFERRED_BACKEND to let you preselect your favourite backend. 0.003 2017-10-16 - Introduce a backend() debug helper to help identifying issues depending on underlying 0.002 2017-10-05 - When using Clone.pm enforce minimum version 0.10. - Fix bug which caused clone() not to be exported in the correct namespace. 0.001 2017-09-27 - First version, released on an unsuspecting world. Clone-Choose-0.008/Makefile.PL0000644000175000017500000001263213174361543015306 0ustar stefanstefanuse strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %RUN_DEPS = ($] < 5.007003 ? ('Clone::PP' => 0) : ('Storable' => 0)); my %CONFIGURE_DEPS = ( 'ExtUtils::MakeMaker' => 0, ); my %BUILD_DEPS = (); my %TEST_DEPS = ( 'Test::More' => 0.90, ); if (-d 'Sandbox') { unless (grep { $_ eq '.' } @INC) { use lib '.'; } eval "use Sandbox::Tumble ();"; $@ and die $@; eval "use File::Path ();"; File::Path->import; -d 't/Clone' and rmtree('t/Clone'); -d 't/Storable' and rmtree('t/Storable'); -d 't/ClonePP' and rmtree('t/ClonePP'); Sandbox::Tumble->tumble(qw(t)); } WriteMakefile1( MIN_PERL_VERSION => '5.008001', META_MERGE => { 'meta-spec' => {version => 2}, dynamic_config => 1, resources => { homepage => 'https://metacpan.org/release/Clone-Choose', repository => { url => 'https://github.com:perl5-utils/Clone-Choose.git', web => 'https://github.com/perl5-utils/Clone-Choose', type => 'git', }, bugtracker => { web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Clone-Choose', mailto => 'bug-Clone-Choose@rt.cpan.org', }, license => 'http://dev.perl.org/licenses/', }, prereqs => { develop => { requires => { 'Test::CPAN::Changes' => 0, 'Test::CheckManifest' => 0, 'Module::CPANTS::Analyse' => '0.96', 'Test::Kwalitee' => 0, 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, 'Test::Pod::Spelling::CommonMistakes' => 0, 'Test::Spelling' => 0, 'Test::Perl::Critic' => 0, 'Test::PerlTidy' => 0, 'Test::WriteVariants' => '0.014', }, }, configure => { requires => {%CONFIGURE_DEPS}, }, build => {requires => {%BUILD_DEPS}}, test => { requires => {%TEST_DEPS}, suggests => { 'Clone' => 0.10, 'Clone::PP' => 0, 'Storable' => 0 } }, runtime => { requires => { %RUN_DEPS, perl => '5.8.1', }, recommends => { 'Module::Runtime' => 0, }, }, }, }, NAME => 'Clone::Choose', VERSION_FROM => 'lib/Clone/Choose.pm', ABSTRACT_FROM => 'lib/Clone/Choose.pm', LICENSE => 'perl', AUTHOR => [q{Jens Rehsack }, q{Stefan Hermes }], CONFIGURE_REQUIRES => \%CONFIGURE_DEPS, PREREQ_PM => \%RUN_DEPS, BUILD_REQUIRES => \%BUILD_DEPS, TEST_REQUIRES => \%TEST_DEPS, test => {TESTS => join(' ', 't/Auto/*.t', 't/*.t', 't/Clone/*.t', 't/Storable/*.t', 't/ClonePP/*.t', 'xt/*.t')}, (-d "Sandbox" ? (realclean => {FILES => "t/Clone t/Storable t/ClonePP M*.bak"}) : ()), ); sub WriteMakefile1 { # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params = @_; my $eumm_version = $ExtUtils::MakeMaker::VERSION; $eumm_version = eval $eumm_version; die "EXTRA_META is deprecated" if (exists($params{EXTRA_META})); die "License not specified" if (!exists($params{LICENSE})); $params{TEST_REQUIRES} and $eumm_version < 6.6303 and $params{BUILD_REQUIRES} = {%{$params{BUILD_REQUIRES} || {}}, %{delete $params{TEST_REQUIRES}}}; #EUMM 6.5502 has problems with BUILD_REQUIRES $params{BUILD_REQUIRES} and $eumm_version < 6.5503 and $params{PREREQ_PM} = {%{$params{PREREQ_PM} || {}}, %{delete $params{BUILD_REQUIRES}}}; ref $params{AUTHOR} and "ARRAY" eq ref $params{AUTHOR} and $eumm_version < 6.5702 and $params{AUTHOR} = join(", ", @{$params{AUTHOR}}); delete $params{CONFIGURE_REQUIRES} if ($eumm_version < 6.52); delete $params{MIN_PERL_VERSION} if ($eumm_version < 6.48); delete $params{META_MERGE} if ($eumm_version < 6.46); delete $params{META_ADD}{prereqs} if ($eumm_version < 6.58); delete $params{META_ADD}{'meta-spec'} if ($eumm_version < 6.58); delete $params{META_ADD} if ($eumm_version < 6.46); delete $params{LICENSE} if ($eumm_version < 6.31); delete $params{AUTHOR} if ($] < 5.005); delete $params{ABSTRACT_FROM} if ($] < 5.005); delete $params{BINARY_LOCATION} if ($] < 5.005); # more or less taken from Moose' Makefile.PL if ($params{CONFLICTS}) { my $ok = CheckConflicts(%params); exit(0) if ($params{PREREQ_FATAL} and not $ok); my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV; unless ($cpan_smoker || $ENV{PERL_MM_USE_DEFAULT}) { sleep 4 unless ($ok); } delete $params{CONFLICTS}; } WriteMakefile(%params); } Clone-Choose-0.008/t/0000755000175000017500000000000013174573774013606 5ustar stefanstefanClone-Choose-0.008/t/ClonePP/0000755000175000017500000000000013174573774015106 5ustar stefanstefanClone-Choose-0.008/t/ClonePP/00-load.t0000644000175000017500000000121713174573742016423 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone::PP"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; use_ok('Clone::Choose') || BAIL_OUT "Couldn't load Clone::Choose"; } diag("Testing Clone::Choose $Clone::Choose::VERSION, Perl $], $^X"); my $backend = Clone::Choose->backend; diag("Using backend $backend version " . $backend->VERSION); done_testing; Clone-Choose-0.008/t/ClonePP/05-scalar.t0000644000175000017500000000157013174573742016760 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone::PP"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $string = "Scalar"; $string = \$string; my $cloned_string = clone $string; ok(refaddr $string != refaddr $cloned_string, "Scalar String"); my $numeric = 3.141; $numeric = \$numeric; my $cloned_numeric = clone $numeric; ok(refaddr $numeric != refaddr $cloned_numeric, "Scalar Numeric"); my $undef = undef; $undef = \$undef; my $cloned_undef = clone $undef; ok(refaddr $undef != refaddr $cloned_undef, "Scalar Undef"); done_testing; Clone-Choose-0.008/t/ClonePP/07-hash.t0000644000175000017500000000374413174573742016445 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone::PP"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $hash = { level => 0, href => { level => 1, href => { level => 2, href => {level => 3}, }, }, }; my $cloned_hash = clone $hash; ok(refaddr $hash != refaddr $cloned_hash, "Clone depth 0"); ok(refaddr($hash->{href}) != refaddr($cloned_hash->{href}), "Clone depth 1"); ok(refaddr($hash->{href}->{href}) != refaddr($cloned_hash->{href}->{href}), "Clone depth 2"); ok(refaddr($hash->{href}->{href}->{href}) != refaddr($cloned_hash->{href}->{href}->{href}), "Clone depth 3"); ok($hash->{level} == $cloned_hash->{level}, "Hash value depth 0"); ok($hash->{href}->{level} == $cloned_hash->{href}->{level}, "Hash value depth 1"); ok($hash->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{level}, "Hash value depth 2"); ok($hash->{href}->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{href}->{level}, "Hash value depth 3"); ok($hash->{level} == 0, "Hash value sanity depth 0"); ok($hash->{href}->{level} == 1, "Hash value sanity depth 1"); ok($hash->{href}->{href}->{level} == 2, "Hash value sanity depth 2"); ok($hash->{href}->{href}->{href}->{level} == 3, "Hash value sanity depth 3"); my $empty_hash = {}; my $cloned_empty_hash = clone $empty_hash; ok(refaddr $empty_hash != refaddr $cloned_empty_hash, "Empty hash clone"); done_testing; Clone-Choose-0.008/t/ClonePP/01-simple.t0000644000175000017500000000110113174573742016766 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone::PP"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my %src = ( simple => "yeah", ary => [qw(foo bar)], hash => {foo => "bar"} ); my $tgt = clone(\%src); is_deeply(\%src, $tgt); done_testing; Clone-Choose-0.008/t/ClonePP/06-array.t0000644000175000017500000000316513174573742016634 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone::PP"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $array = [1, ["two", [3, ["four"],],],]; my $cloned_array = clone $array; ok(refaddr $array != refaddr $cloned_array, "Clone depth 0"); ok(refaddr($array->[1]) != refaddr($cloned_array->[1]), "Clone depth 1"); ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]), "Clone depth 2"); ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3"); ok($array->[0] == $cloned_array->[0], "Array value depth 0"); ok($array->[1][0] eq $cloned_array->[1][0], "Array value depth 1"); ok($array->[1][1][0] == $cloned_array->[1][1][0], "Array value depth 2"); ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3"); ok($cloned_array->[0] == 1, "Array value sanity depth 0"); ok($cloned_array->[1][0] eq "two", "Array value sanity depth 1"); ok($cloned_array->[1][1][0] == 3, "Array value sanity depth 2"); ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3"); my $empty_array = []; my $cloned_empty_array = clone $empty_array; ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone"); done_testing; Clone-Choose-0.008/t/Auto/0000755000175000017500000000000013174573774014516 5ustar stefanstefanClone-Choose-0.008/t/Auto/00-load.t0000644000175000017500000000102313174573742016026 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; use_ok('Clone::Choose') || BAIL_OUT "Couldn't load Clone::Choose"; } diag("Testing Clone::Choose $Clone::Choose::VERSION, Perl $], $^X"); my $backend = Clone::Choose->backend; diag("Using backend $backend version " . $backend->VERSION); done_testing; Clone-Choose-0.008/t/Auto/05-scalar.t0000644000175000017500000000137413174573742016372 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $string = "Scalar"; $string = \$string; my $cloned_string = clone $string; ok(refaddr $string != refaddr $cloned_string, "Scalar String"); my $numeric = 3.141; $numeric = \$numeric; my $cloned_numeric = clone $numeric; ok(refaddr $numeric != refaddr $cloned_numeric, "Scalar Numeric"); my $undef = undef; $undef = \$undef; my $cloned_undef = clone $undef; ok(refaddr $undef != refaddr $cloned_undef, "Scalar Undef"); done_testing; Clone-Choose-0.008/t/Auto/07-hash.t0000644000175000017500000000355013174573742016050 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $hash = { level => 0, href => { level => 1, href => { level => 2, href => {level => 3}, }, }, }; my $cloned_hash = clone $hash; ok(refaddr $hash != refaddr $cloned_hash, "Clone depth 0"); ok(refaddr($hash->{href}) != refaddr($cloned_hash->{href}), "Clone depth 1"); ok(refaddr($hash->{href}->{href}) != refaddr($cloned_hash->{href}->{href}), "Clone depth 2"); ok(refaddr($hash->{href}->{href}->{href}) != refaddr($cloned_hash->{href}->{href}->{href}), "Clone depth 3"); ok($hash->{level} == $cloned_hash->{level}, "Hash value depth 0"); ok($hash->{href}->{level} == $cloned_hash->{href}->{level}, "Hash value depth 1"); ok($hash->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{level}, "Hash value depth 2"); ok($hash->{href}->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{href}->{level}, "Hash value depth 3"); ok($hash->{level} == 0, "Hash value sanity depth 0"); ok($hash->{href}->{level} == 1, "Hash value sanity depth 1"); ok($hash->{href}->{href}->{level} == 2, "Hash value sanity depth 2"); ok($hash->{href}->{href}->{href}->{level} == 3, "Hash value sanity depth 3"); my $empty_hash = {}; my $cloned_empty_hash = clone $empty_hash; ok(refaddr $empty_hash != refaddr $cloned_empty_hash, "Empty hash clone"); done_testing; Clone-Choose-0.008/t/Auto/01-simple.t0000644000175000017500000000070513174573742016407 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my %src = ( simple => "yeah", ary => [qw(foo bar)], hash => {foo => "bar"} ); my $tgt = clone(\%src); is_deeply(\%src, $tgt); done_testing; Clone-Choose-0.008/t/Auto/06-array.t0000644000175000017500000000277113174573742016246 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $array = [1, ["two", [3, ["four"],],],]; my $cloned_array = clone $array; ok(refaddr $array != refaddr $cloned_array, "Clone depth 0"); ok(refaddr($array->[1]) != refaddr($cloned_array->[1]), "Clone depth 1"); ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]), "Clone depth 2"); ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3"); ok($array->[0] == $cloned_array->[0], "Array value depth 0"); ok($array->[1][0] eq $cloned_array->[1][0], "Array value depth 1"); ok($array->[1][1][0] == $cloned_array->[1][1][0], "Array value depth 2"); ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3"); ok($cloned_array->[0] == 1, "Array value sanity depth 0"); ok($cloned_array->[1][0] eq "two", "Array value sanity depth 1"); ok($cloned_array->[1][1][0] == 3, "Array value sanity depth 2"); ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3"); my $empty_array = []; my $cloned_empty_array = clone $empty_array; ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone"); done_testing; Clone-Choose-0.008/t/02-load-with-clone.t0000644000175000017500000000041513165434762017171 0ustar stefanstefan#!perl use strict; use warnings; use Test::More; eval "use Clone;"; $@ and plan skip_all => "No Clone found. Can't prove load successfull with :Clone."; use_ok("Clone::Choose", qw(:Clone)) || plan skip_all => "Couldn't use Clone::Choose qw(:Clone)."; done_testing; Clone-Choose-0.008/t/Clone/0000755000175000017500000000000013174573774014646 5ustar stefanstefanClone-Choose-0.008/t/Clone/00-load.t0000644000175000017500000000121313174573742016157 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; use_ok('Clone::Choose') || BAIL_OUT "Couldn't load Clone::Choose"; } diag("Testing Clone::Choose $Clone::Choose::VERSION, Perl $], $^X"); my $backend = Clone::Choose->backend; diag("Using backend $backend version " . $backend->VERSION); done_testing; Clone-Choose-0.008/t/Clone/05-scalar.t0000644000175000017500000000156413174573742016523 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $string = "Scalar"; $string = \$string; my $cloned_string = clone $string; ok(refaddr $string != refaddr $cloned_string, "Scalar String"); my $numeric = 3.141; $numeric = \$numeric; my $cloned_numeric = clone $numeric; ok(refaddr $numeric != refaddr $cloned_numeric, "Scalar Numeric"); my $undef = undef; $undef = \$undef; my $cloned_undef = clone $undef; ok(refaddr $undef != refaddr $cloned_undef, "Scalar Undef"); done_testing; Clone-Choose-0.008/t/Clone/07-hash.t0000644000175000017500000000374013174573742016201 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $hash = { level => 0, href => { level => 1, href => { level => 2, href => {level => 3}, }, }, }; my $cloned_hash = clone $hash; ok(refaddr $hash != refaddr $cloned_hash, "Clone depth 0"); ok(refaddr($hash->{href}) != refaddr($cloned_hash->{href}), "Clone depth 1"); ok(refaddr($hash->{href}->{href}) != refaddr($cloned_hash->{href}->{href}), "Clone depth 2"); ok(refaddr($hash->{href}->{href}->{href}) != refaddr($cloned_hash->{href}->{href}->{href}), "Clone depth 3"); ok($hash->{level} == $cloned_hash->{level}, "Hash value depth 0"); ok($hash->{href}->{level} == $cloned_hash->{href}->{level}, "Hash value depth 1"); ok($hash->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{level}, "Hash value depth 2"); ok($hash->{href}->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{href}->{level}, "Hash value depth 3"); ok($hash->{level} == 0, "Hash value sanity depth 0"); ok($hash->{href}->{level} == 1, "Hash value sanity depth 1"); ok($hash->{href}->{href}->{level} == 2, "Hash value sanity depth 2"); ok($hash->{href}->{href}->{href}->{level} == 3, "Hash value sanity depth 3"); my $empty_hash = {}; my $cloned_empty_hash = clone $empty_hash; ok(refaddr $empty_hash != refaddr $cloned_empty_hash, "Empty hash clone"); done_testing; Clone-Choose-0.008/t/Clone/01-simple.t0000644000175000017500000000107513174573742016540 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my %src = ( simple => "yeah", ary => [qw(foo bar)], hash => {foo => "bar"} ); my $tgt = clone(\%src); is_deeply(\%src, $tgt); done_testing; Clone-Choose-0.008/t/Clone/06-array.t0000644000175000017500000000316113174573742016370 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Clone"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $array = [1, ["two", [3, ["four"],],],]; my $cloned_array = clone $array; ok(refaddr $array != refaddr $cloned_array, "Clone depth 0"); ok(refaddr($array->[1]) != refaddr($cloned_array->[1]), "Clone depth 1"); ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]), "Clone depth 2"); ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3"); ok($array->[0] == $cloned_array->[0], "Array value depth 0"); ok($array->[1][0] eq $cloned_array->[1][0], "Array value depth 1"); ok($array->[1][1][0] == $cloned_array->[1][1][0], "Array value depth 2"); ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3"); ok($cloned_array->[0] == 1, "Array value sanity depth 0"); ok($cloned_array->[1][0] eq "two", "Array value sanity depth 1"); ok($cloned_array->[1][1][0] == 3, "Array value sanity depth 2"); ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3"); my $empty_array = []; my $cloned_empty_array = clone $empty_array; ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone"); done_testing; Clone-Choose-0.008/t/inline/0000755000175000017500000000000013174573774015064 5ustar stefanstefanClone-Choose-0.008/t/inline/00-load.t0000644000175000017500000000071513174361543016375 0ustar stefanstefanuse Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; use_ok('Clone::Choose') || BAIL_OUT "Couldn't load Clone::Choose"; } diag("Testing Clone::Choose $Clone::Choose::VERSION, Perl $], $^X"); my $backend = Clone::Choose->backend; diag("Using backend $backend version " . $backend->VERSION); done_testing; Clone-Choose-0.008/t/inline/05-scalar.t0000644000175000017500000000126613174361543016732 0ustar stefanstefanuse Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $string = "Scalar"; $string = \$string; my $cloned_string = clone $string; ok(refaddr $string != refaddr $cloned_string, "Scalar String"); my $numeric = 3.141; $numeric = \$numeric; my $cloned_numeric = clone $numeric; ok(refaddr $numeric != refaddr $cloned_numeric, "Scalar Numeric"); my $undef = undef; $undef = \$undef; my $cloned_undef = clone $undef; ok(refaddr $undef != refaddr $cloned_undef, "Scalar Undef"); done_testing; Clone-Choose-0.008/t/inline/07-hash.t0000644000175000017500000000344213174361543016410 0ustar stefanstefanuse Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $hash = { level => 0, href => { level => 1, href => { level => 2, href => {level => 3}, }, }, }; my $cloned_hash = clone $hash; ok(refaddr $hash != refaddr $cloned_hash, "Clone depth 0"); ok(refaddr($hash->{href}) != refaddr($cloned_hash->{href}), "Clone depth 1"); ok(refaddr($hash->{href}->{href}) != refaddr($cloned_hash->{href}->{href}), "Clone depth 2"); ok(refaddr($hash->{href}->{href}->{href}) != refaddr($cloned_hash->{href}->{href}->{href}), "Clone depth 3"); ok($hash->{level} == $cloned_hash->{level}, "Hash value depth 0"); ok($hash->{href}->{level} == $cloned_hash->{href}->{level}, "Hash value depth 1"); ok($hash->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{level}, "Hash value depth 2"); ok($hash->{href}->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{href}->{level}, "Hash value depth 3"); ok($hash->{level} == 0, "Hash value sanity depth 0"); ok($hash->{href}->{level} == 1, "Hash value sanity depth 1"); ok($hash->{href}->{href}->{level} == 2, "Hash value sanity depth 2"); ok($hash->{href}->{href}->{href}->{level} == 3, "Hash value sanity depth 3"); my $empty_hash = {}; my $cloned_empty_hash = clone $empty_hash; ok(refaddr $empty_hash != refaddr $cloned_empty_hash, "Empty hash clone"); done_testing; Clone-Choose-0.008/t/inline/01-simple.t0000644000175000017500000000057713174573267016766 0ustar stefanstefanuse Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my %src = ( simple => "yeah", ary => [qw(foo bar)], hash => {foo => "bar"} ); my $tgt = clone(\%src); is_deeply(\%src, $tgt); done_testing; Clone-Choose-0.008/t/inline/06-array.t0000644000175000017500000000266313174361543016606 0ustar stefanstefanuse Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $array = [1, ["two", [3, ["four"],],],]; my $cloned_array = clone $array; ok(refaddr $array != refaddr $cloned_array, "Clone depth 0"); ok(refaddr($array->[1]) != refaddr($cloned_array->[1]), "Clone depth 1"); ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]), "Clone depth 2"); ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3"); ok($array->[0] == $cloned_array->[0], "Array value depth 0"); ok($array->[1][0] eq $cloned_array->[1][0], "Array value depth 1"); ok($array->[1][1][0] == $cloned_array->[1][1][0], "Array value depth 2"); ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3"); ok($cloned_array->[0] == 1, "Array value sanity depth 0"); ok($cloned_array->[1][0] eq "two", "Array value sanity depth 1"); ok($cloned_array->[1][1][0] == 3, "Array value sanity depth 2"); ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3"); my $empty_array = []; my $cloned_empty_array = clone $empty_array; ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone"); done_testing; Clone-Choose-0.008/t/04-load-with-clone-pp.t0000644000175000017500000000044113165435100017572 0ustar stefanstefan#!perl use strict; use warnings; use Test::More; eval "use Clone::PP;"; $@ and plan skip_all => "No Clone::PP found. Can't prove load successfull with :Clone::PP."; use_ok("Clone::Choose", qw(:Clone::PP)) || plan skip_all => "Couldn't use Clone::Choose qw(:Clone::PP)."; done_testing; Clone-Choose-0.008/t/03-load-with-storable.t0000644000175000017500000000043613165435050017677 0ustar stefanstefan#! perl use strict; use warnings; use Test::More; eval "use Storable;"; $@ and plan skip_all => "No Storable found. Can't prove load successfully with :Storable."; use_ok("Clone::Choose", qw(:Storable)) || plan skip_all => "Couldn't use Clone::Choose qw(:Storable)."; done_testing; Clone-Choose-0.008/t/Storable/0000755000175000017500000000000013174573774015361 5ustar stefanstefanClone-Choose-0.008/t/Storable/00-load.t0000644000175000017500000000121613174573742016675 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Storable"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; use_ok('Clone::Choose') || BAIL_OUT "Couldn't load Clone::Choose"; } diag("Testing Clone::Choose $Clone::Choose::VERSION, Perl $], $^X"); my $backend = Clone::Choose->backend; diag("Using backend $backend version " . $backend->VERSION); done_testing; Clone-Choose-0.008/t/Storable/05-scalar.t0000644000175000017500000000156713174573742017241 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Storable"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $string = "Scalar"; $string = \$string; my $cloned_string = clone $string; ok(refaddr $string != refaddr $cloned_string, "Scalar String"); my $numeric = 3.141; $numeric = \$numeric; my $cloned_numeric = clone $numeric; ok(refaddr $numeric != refaddr $cloned_numeric, "Scalar Numeric"); my $undef = undef; $undef = \$undef; my $cloned_undef = clone $undef; ok(refaddr $undef != refaddr $cloned_undef, "Scalar Undef"); done_testing; Clone-Choose-0.008/t/Storable/07-hash.t0000644000175000017500000000374313174573742016717 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Storable"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $hash = { level => 0, href => { level => 1, href => { level => 2, href => {level => 3}, }, }, }; my $cloned_hash = clone $hash; ok(refaddr $hash != refaddr $cloned_hash, "Clone depth 0"); ok(refaddr($hash->{href}) != refaddr($cloned_hash->{href}), "Clone depth 1"); ok(refaddr($hash->{href}->{href}) != refaddr($cloned_hash->{href}->{href}), "Clone depth 2"); ok(refaddr($hash->{href}->{href}->{href}) != refaddr($cloned_hash->{href}->{href}->{href}), "Clone depth 3"); ok($hash->{level} == $cloned_hash->{level}, "Hash value depth 0"); ok($hash->{href}->{level} == $cloned_hash->{href}->{level}, "Hash value depth 1"); ok($hash->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{level}, "Hash value depth 2"); ok($hash->{href}->{href}->{href}->{level} == $cloned_hash->{href}->{href}->{href}->{level}, "Hash value depth 3"); ok($hash->{level} == 0, "Hash value sanity depth 0"); ok($hash->{href}->{level} == 1, "Hash value sanity depth 1"); ok($hash->{href}->{href}->{level} == 2, "Hash value sanity depth 2"); ok($hash->{href}->{href}->{href}->{level} == 3, "Hash value sanity depth 3"); my $empty_hash = {}; my $cloned_empty_hash = clone $empty_hash; ok(refaddr $empty_hash != refaddr $cloned_empty_hash, "Empty hash clone"); done_testing; Clone-Choose-0.008/t/Storable/01-simple.t0000644000175000017500000000110013174573742017240 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Storable"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my %src = ( simple => "yeah", ary => [qw(foo bar)], hash => {foo => "bar"} ); my $tgt = clone(\%src); is_deeply(\%src, $tgt); done_testing; Clone-Choose-0.008/t/Storable/06-array.t0000644000175000017500000000316413174573742017106 0ustar stefanstefan#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} = "Storable"; } END { delete $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} } # for VMS use Scalar::Util qw(refaddr); use Test::More; BEGIN { $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;"; $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found."; } use Clone::Choose; my $array = [1, ["two", [3, ["four"],],],]; my $cloned_array = clone $array; ok(refaddr $array != refaddr $cloned_array, "Clone depth 0"); ok(refaddr($array->[1]) != refaddr($cloned_array->[1]), "Clone depth 1"); ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]), "Clone depth 2"); ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3"); ok($array->[0] == $cloned_array->[0], "Array value depth 0"); ok($array->[1][0] eq $cloned_array->[1][0], "Array value depth 1"); ok($array->[1][1][0] == $cloned_array->[1][1][0], "Array value depth 2"); ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3"); ok($cloned_array->[0] == 1, "Array value sanity depth 0"); ok($cloned_array->[1][0] eq "two", "Array value sanity depth 1"); ok($cloned_array->[1][1][0] == 3, "Array value sanity depth 2"); ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3"); my $empty_array = []; my $cloned_empty_array = clone $empty_array; ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone"); done_testing; Clone-Choose-0.008/META.json0000644000175000017500000000434613174573774014773 0ustar stefanstefan{ "abstract" : "Choose appropriate clone utility", "author" : [ "Jens Rehsack ", "Stefan Hermes " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Clone-Choose", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Module::CPANTS::Analyse" : "0.96", "Test::CPAN::Changes" : "0", "Test::CheckManifest" : "0", "Test::Kwalitee" : "0", "Test::Perl::Critic" : "0", "Test::PerlTidy" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0", "Test::WriteVariants" : "0.014" } }, "runtime" : { "recommends" : { "Module::Runtime" : "0" }, "requires" : { "Storable" : "0", "perl" : "v5.8.1" } }, "test" : { "requires" : { "Test::More" : "0.9" }, "suggests" : { "Clone" : "0.1", "Clone::PP" : "0", "Storable" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Clone-Choose@rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=Clone-Choose" }, "homepage" : "https://metacpan.org/release/Clone-Choose", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "https://github.com:perl5-utils/Clone-Choose.git", "web" : "https://github.com/perl5-utils/Clone-Choose" } }, "version" : "0.008", "x_serialization_backend" : "JSON::PP version 2.27400" } Clone-Choose-0.008/README.md0000644000175000017500000000757513173641363014625 0ustar stefanstefan# NAME Clone::Choose - Choose appropriate clone utility # SYNOPSIS use Clone::Choose; my $data = { value => 42, href => { set => [ 'foo', 'bar' ], value => 'baz', }, }; my $cloned_data = clone $data; # it's also possible to use Clone::Choose and pass a clone preference use Clone::Choose qw(:Storable); # DESCRIPTION `Clone::Choose` checks several different modules which provides a `clone()` function and selects an appropriate one. The default preference is Clone Storable Clone::PP This list might evolve in future. Please see ["EXPORTS"](#exports) how to pick a particular one. # EXPORTS `Clone::Choose` exports `clone()` by default. One can explicitly import `clone` by using use Clone::Choose qw(clone); or pick a particular `clone` implementation use Clone::Choose qw(:Storable clone); The exported implementation is resolved dynamically, which means that any using module can either rely on the default backend preference or choose a particular one. It is also possible to select a particular `clone` backend by setting the environment variable CLONE\_CHOOSE\_PREFERRED\_BACKEND to your preferred backend. This also means, an already chosen import can't be modified like use Clone::Choose qw(clone :Storable); When one seriously needs different clone implementations, our _recommended_ way to use them would be: use Clone::Choose (); # do not import my ($xs_clone, $st_clone); { local @Clone::Choose::BACKENDS = (Clone => "clone"); $xs_clone = Clone::Choose->can("clone"); } { local @Clone::Choose::BACKENDS = (Storable => "dclone"); $st_clone = Clone::Choose->can("clone"); } Don't misinterpret _recommended_ - modifying `@Clone::Choose::BACKENDS` has a lot of pitfalls and is unreliable beside such small examples. Do not hesitate open a request with an appropriate proposal for choosing implementations dynamically. The use of `@Clone::Choose::BACKENDS` is discouraged and will be deprecated as soon as anyone provides a better idea. # PACKAGE METHODS ## backend `backend` tells the caller about the dynamic chosen backend: use Clone::Choose; say Clone::Choose->backend; # Clone This method currently exists for debug purposes only. ## get\_backends `get_backends` returns a list of the currently supported backends. # AUTHOR Jens Rehsack Stefan Hermes # BUGS Please report any bugs or feature requests to `bug-Clone-Choose at rt.cpan.org`, or through the web interface at [http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Clone-Choose](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Clone-Choose). I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. # SUPPORT You can find documentation for this module with the perldoc command. perldoc Clone::Choose You can also look for information at: - RT: CPAN's request tracker [http://rt.cpan.org/NoAuth/Bugs.html?Dist=Clone-Choose](http://rt.cpan.org/NoAuth/Bugs.html?Dist=Clone-Choose) - AnnoCPAN: Annotated CPAN documentation [http://annocpan.org/dist/Clone-Choose](http://annocpan.org/dist/Clone-Choose) - CPAN Ratings [http://cpanratings.perl.org/d/Clone-Choose](http://cpanratings.perl.org/d/Clone-Choose) - Search CPAN [http://search.cpan.org/dist/Clone-Choose/](http://search.cpan.org/dist/Clone-Choose/) # LICENSE AND COPYRIGHT Copyright 2017 Jens Rehsack Copyright 2017 Stefan Hermes This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. # SEE ALSO [Clone](https://metacpan.org/pod/Clone), [Clone::PP](https://metacpan.org/pod/Clone::PP), [Storable](https://metacpan.org/pod/Storable) Clone-Choose-0.008/lib/0000755000175000017500000000000013174573774014111 5ustar stefanstefanClone-Choose-0.008/lib/Clone/0000755000175000017500000000000013174573774015151 5ustar stefanstefanClone-Choose-0.008/lib/Clone/Choose.pm0000644000175000017500000001613613174573342016725 0ustar stefanstefanpackage Clone::Choose; use strict; use warnings; use Carp (); our $VERSION = "0.008"; $VERSION = eval $VERSION; our @BACKENDS = ( Clone => [0.10, "clone"], Storable => "dclone", "Clone::PP" => "clone", ); my $use_m; BEGIN { unless ($use_m) { eval "use Module::Runtime (); 1;" and $use_m = Module::Runtime->can("use_module") unless $ENV{CLONE_CHOOSE_NO_MODULE_RUNTIME}; $use_m ||= sub { my ($pkg, @imports) = @_; my $use_stmt = "use $pkg"; @imports and $use_stmt = join(" ", $use_stmt, @imports); eval $use_stmt; $@ and die $@; 1; }; } } sub backend { my $self = shift; my @backends = @BACKENDS; if ($ENV{CLONE_CHOOSE_PREFERRED_BACKEND}) { my $favourite = $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; my %b = @backends; Carp::croak "$favourite not found" unless $b{$favourite}; @backends = ($favourite => $b{$favourite}); } while (my ($pkg, $rout) = splice @backends, 0, 2) { eval { $use_m->($pkg, ref $rout ? ($rout->[0]) : ()); 1; } or next; my $fn = $pkg->can(ref $rout ? $rout->[1] : $rout); $fn or next; return $pkg; } return; } sub can { my $self = shift; my $name = shift; my @backends = @BACKENDS; return __PACKAGE__->SUPER::can($name) unless $name eq "clone"; if ($ENV{CLONE_CHOOSE_PREFERRED_BACKEND}) { my $favourite = $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; my %b = @backends; Carp::croak "$favourite not found" unless $b{$favourite}; @backends = ($favourite => $b{$favourite}); } my $fn; while (my ($pkg, $rout) = splice @backends, 0, 2) { eval { $use_m->($pkg, ref $rout ? ($rout->[0]) : ()); 1; } or next; $fn = $pkg->can(ref $rout ? $rout->[1] : $rout); $fn or next; last; } return $fn; } sub import { my ($me, @params) = @_; my $tgt = caller(0); my @B = @BACKENDS; local @BACKENDS = @B; push @params, "clone" unless grep { /^clone$/ } @params; while (my $param = shift @params) { if ($param =~ m/^:(.*)$/) { my $favourite = $1; $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} ne $favourite and Carp::croak "Environment CLONE_CHOOSE_PREFERRED_BACKEND($ENV{CLONE_CHOOSE_PREFERRED_BACKEND}) not equal to imported ($favourite)"; my %b = @BACKENDS; Carp::croak "$favourite not found" unless $b{$favourite}; @BACKENDS = ($favourite => $b{$favourite}); } elsif ($param eq "clone") { my $fn = __PACKAGE__->can("clone"); $fn or Carp::croak "Cannot find an apropriate clone()."; no strict "refs"; *{"${tgt}::clone"} = $fn; @params and Carp::croak "Parameters left after clone. Please see description."; return; } else { Carp::croak "$param is not exportable by " . __PACKAGE__; } } } sub get_backends { my $self = shift; my %backends = @BACKENDS; if ($ENV{CLONE_CHOOSE_PREFERRED_BACKEND}) { my $favourite = $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; Carp::croak "$favourite not found" unless $backends{$favourite}; %backends = ($favourite => $backends{$favourite}); } return keys %backends; } 1; __END__ =head1 NAME Clone::Choose - Choose appropriate clone utility =head1 SYNOPSIS use Clone::Choose; my $data = { value => 42, href => { set => [ 'foo', 'bar' ], value => 'baz', }, }; my $cloned_data = clone $data; # it's also possible to use Clone::Choose and pass a clone preference use Clone::Choose qw(:Storable); =head1 DESCRIPTION C checks several different modules which provides a C function and selects an appropriate one. The default preference is Clone Storable Clone::PP This list might evolve in future. Please see L how to pick a particular one. =head1 EXPORTS C exports C by default. One can explicitly import C by using use Clone::Choose qw(clone); or pick a particular C implementation use Clone::Choose qw(:Storable clone); The exported implementation is resolved dynamically, which means that any using module can either rely on the default backend preference or choose a particular one. It is also possible to select a particular C backend by setting the environment variable CLONE_CHOOSE_PREFERRED_BACKEND to your preferred backend. This also means, an already chosen import can't be modified like use Clone::Choose qw(clone :Storable); When one seriously needs different clone implementations, our I way to use them would be: use Clone::Choose (); # do not import my ($xs_clone, $st_clone); { local @Clone::Choose::BACKENDS = (Clone => "clone"); $xs_clone = Clone::Choose->can("clone"); } { local @Clone::Choose::BACKENDS = (Storable => "dclone"); $st_clone = Clone::Choose->can("clone"); } Don't misinterpret I - modifying C<@Clone::Choose::BACKENDS> has a lot of pitfalls and is unreliable beside such small examples. Do not hesitate open a request with an appropriate proposal for choosing implementations dynamically. The use of C<@Clone::Choose::BACKENDS> is discouraged and will be deprecated as soon as anyone provides a better idea. =head1 PACKAGE METHODS =head2 backend C tells the caller about the dynamic chosen backend: use Clone::Choose; say Clone::Choose->backend; # Clone This method currently exists for debug purposes only. =head2 get_backends C returns a list of the currently supported backends. =head1 AUTHOR Jens Rehsack Stefan Hermes =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Clone::Choose You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2017 Jens Rehsack Copyright 2017 Stefan Hermes This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =head1 SEE ALSO L, L, L =cut