3 # Copyright 2002, Larry Wall.
5 # You may redistribute only under the same terms as Perl 5, as specified
6 # in the README file that comes with the distribution.
12 @INC = ('.', '../lib', '../ext/Storable/t');
14 if ($Config::Config{'extensions'} !~ /\bStorable\b/) {
15 print "1..0 # Skip: Storable was not built\n";
19 unless (eval "require Hash::Util") {
20 if ($@ =~ /Can\'t locate Hash\/Util\.pm in \@INC/) {
21 print "1..0 # Skip: No Hash::Util\n";
33 use Storable qw(dclone);
34 use Hash::Util qw(lock_hash unlock_value);
38 my %hash = (question => '?', answer => 42, extra => 'junk', undef => undef);
40 unlock_value %hash, 'answer';
41 unlock_value %hash, 'extra';
42 delete $hash{'extra'};
46 package Restrict_Test;
49 return (undef, $_[0]);
56 my $copy = dclone $hash;
58 my @in_keys = sort keys %$hash;
59 my @out_keys = sort keys %$copy;
60 unless (ok ++$test, "@in_keys" eq "@out_keys") {
61 print "# Failed: keys mis-match after deep clone.\n";
62 print "# Original keys: @in_keys\n";
63 print "# Copy's keys: @out_keys\n";
66 # $copy = $hash; # used in initial debug of the tests
68 ok ++$test, Internals::SvREADONLY(%$copy), "cloned hash restricted?";
70 ok ++$test, Internals::SvREADONLY($copy->{question}),
71 "key 'question' not locked in copy?";
73 ok ++$test, !Internals::SvREADONLY($copy->{answer}),
74 "key 'answer' not locked in copy?";
76 eval { $copy->{extra} = 15 } ;
77 unless (ok ++$test, !$@, "Can assign to reserved key 'extra'?") {
80 print "# \$\@: $diag\n";
83 eval { $copy->{nono} = 7 } ;
84 ok ++$test, $@, "Can not assign to invalid key 'nono'?";
86 ok ++$test, exists $copy->{undef},
89 ok ++$test, !defined $copy->{undef},
90 "value for key 'undef' is undefined";
93 for $Storable::canonical (0, 1) {
94 print "# \$Storable::canonical = $Storable::canonical\n";
97 # bless {}, "Restrict_Test";