3 # Copyright (c) 1995-2000, Raphael Manfredi
5 # You may redistribute only under the same terms as Perl 5, as specified
6 # in the README file that comes with the distribution.
11 unshift @INC, 't/compat' if $] < 5.006002;
12 require Config; import Config;
13 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
14 print "1..0 # Skip: Storable was not built\n";
20 use Storable qw(store retrieve store_fd nstore_fd fd_retrieve);
22 use Test::More tests => 21;
27 $c->{attribute} = 'attrval';
28 %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
29 @a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
30 $b, \$a, $a, $c, \$c, \%a);
32 isnt(store(\@a, 'store'), undef);
37 $root = retrieve('store');
45 1 while unlink 'store';
47 package FOO; @ISA = qw(Storable);
51 $self->{key} = \%main::a;
58 isnt($foo->store('store'), undef);
60 isnt(open(OUT, '>>store'), undef);
63 isnt(store_fd(\@a, ::OUT), undef);
64 isnt(nstore_fd($foo, ::OUT), undef);
65 isnt(nstore_fd(\%a, ::OUT), undef);
67 isnt(close(OUT), undef);
69 isnt(open(OUT, 'store'), undef);
71 $r = fd_retrieve(::OUT);
73 is(&dump($r), &dump($foo));
75 $r = fd_retrieve(::OUT);
77 is(&dump($r), &dump(\@a));
79 $r = fd_retrieve(main::OUT);
81 is(&dump($r), &dump($foo));
83 $r = fd_retrieve(::OUT);
85 is(&dump($r), &dump(\%a));
87 eval { $r = fd_retrieve(::OUT); };
90 close OUT or die "Could not close: $!";
91 END { 1 while unlink 'store' }