4 # Copyright 2002, Larry Wall.
6 # You may redistribute only under the same terms as Perl 5, as specified
7 # in the README file that comes with the distribution.
14 require Config; import Config;
15 if ($Config{'extensions'} !~ /\bStorable\b/) {
16 print "1..0 # Skip: Storable was not built\n";
19 require 'lib/st-dump.pl';
23 use Storable qw(dclone);
24 use Hash::Util qw(lock_hash unlock_value);
28 my %hash = (question => '?', answer => 42, extra => 'junk', undef => undef);
30 unlock_value %hash, 'answer';
31 unlock_value %hash, 'extra';
32 delete $hash{'extra'};
36 package Restrict_Test;
39 return (undef, $_[0]);
46 my $copy = dclone $hash;
48 my @in_keys = sort keys %$hash;
49 my @out_keys = sort keys %$copy;
50 unless (ok ++$test, "@in_keys" eq "@out_keys") {
51 print "# Failed: keys mis-match after deep clone.\n";
52 print "# Original keys: @in_keys\n";
53 print "# Copy's keys: @out_keys\n";
56 # $copy = $hash; # used in initial debug of the tests
58 ok ++$test, Internals::SvREADONLY(%$copy), "cloned hash restricted?";
60 ok ++$test, Internals::SvREADONLY($copy->{question}),
61 "key 'question' not locked in copy?";
63 ok ++$test, !Internals::SvREADONLY($copy->{answer}),
64 "key 'answer' not locked in copy?";
66 eval { $copy->{extra} = 15 } ;
67 unless (ok ++$test, !$@, "Can assign to reserved key 'extra'?") {
70 print "# \$@: $diag\n";
73 eval { $copy->{nono} = 7 } ;
74 ok ++$test, $@, "Can not assign to invalid key 'nono'?";
76 ok ++$test, exists $copy->{undef},
79 ok ++$test, !defined $copy->{undef},
80 "value for key 'undef' is undefined";
83 for $Storable::canonical (0, 1) {
84 print "# \$Storable::canonical = $Storable::canonical\n";
87 # bless {}, "Restrict_Test";