3 # $Id: recurse.t,v 1.0.1.1 2000/09/17 16:48:05 ram Exp $
5 # Copyright (c) 1995-2000, Raphael Manfredi
7 # You may redistribute only under the same terms as Perl 5, as specified
8 # in the README file that comes with the distribution.
11 # Revision 1.0.1.1 2000/09/17 16:48:05 ram
12 # patch1: added test case for store hook bug
15 # Revision 1.0 2000/09/01 19:40:42 ram
16 # Baseline for first official release.
23 require Config; import Config;
24 if ($Config{'extensions'} !~ /\bStorable\b/) {
25 print "1..0 # Skip: Storable was not built\n";
28 require 'lib/st-dump.pl';
33 use Storable qw(freeze thaw dclone);
39 use Storable qw(freeze thaw);
43 sub make { bless [], shift }
48 die "STORABLE_freeze" unless Storable::is_storing;
49 return (freeze(\@x), $self);
56 die "STORABLE_thaw #1" unless $obj eq $self;
59 die "STORABLE_thaw #2" unless ref $a eq 'ARRAY';
60 die "STORABLE_thaw #3" unless @$a == 2 && $a->[0] eq 'a' && $a->[1] == 1;
62 die "STORABLE_thaw #4" unless Storable::is_retrieving;
69 sub make { bless {}, shift }
75 return ("", \@x, $self);
80 my ($cloning, $undef, $a, $obj) = @_;
81 die "STORABLE_thaw #1" unless $obj eq $self;
82 die "STORABLE_thaw #2" unless ref $a eq 'ARRAY' || @$a != 2;
88 use Storable qw(dclone);
91 my $self = bless {}, shift;
93 $self->{sync} = OBJ_SYNC->make;
100 my $t = dclone($self->{sync});
101 return ("", [$t, $self->{ext}], $self, $self->{ext});
106 my ($cloning, $undef, $a, $obj, $ext) = @_;
107 die "STORABLE_thaw #1" unless $obj eq $self;
108 die "STORABLE_thaw #2" unless ref $a eq 'ARRAY';
110 ($self->{sync}, $self->{ext}) = @$a;
115 use Storable qw(freeze thaw);
121 sub make { bless [], shift }
123 sub STORABLE_freeze {
126 return (freeze($self), $self) if ++$recursed < $MAX;
127 return ("no", $self);
134 die "STORABLE_thaw #1" unless $obj eq $self;
135 $self->[0] = thaw($x) if $x ne "no";
141 my $real = OBJ_REAL->make;
142 my $x = freeze $real;
147 ok 3, $y->[0] eq 'a';
150 my $sync = OBJ_SYNC->make;
156 ok 7, $y->{ok} == $y;
159 $sync = OBJ_SYNC2->make($ext);
160 $x = freeze [$sync, $ext];
166 ok 10, $y->{ok} == $y;
167 ok 11, ref $y->{sync} eq 'OBJ_SYNC';
168 ok 12, $y->{ext} == $z->[1];
170 $real = OBJ_REAL2->make;
173 ok 14, $OBJ_REAL2::recursed == $OBJ_REAL2::MAX;
174 ok 15, $OBJ_REAL2::hook_called == $OBJ_REAL2::MAX;
178 ok 17, $OBJ_REAL2::recursed == 0;
182 ok 19, ref $x eq 'OBJ_REAL2';
183 ok 20, $OBJ_REAL2::recursed == 0;
184 ok 21, $OBJ_REAL2::hook_called == 2 * $OBJ_REAL2::MAX;
186 ok 22, !Storable::is_storing;
187 ok 23, !Storable::is_retrieving;
190 # The following was a test-case that Salvador Ortiz Garcia <sog@msg.com.mx>
191 # sent me, along with a proposed fix.
199 return bless {dat => $dat}, $class;
209 Foo->new(2), # Second instance of a Foo
214 sub STORABLE_freeze {
215 my($self,$clonning) = @_;
216 return "$self->{a}", $self->{b};
220 my($self,$clonning,$dummy,$o) = @_;
228 my $bar2 = thaw freeze $bar;
230 ok 24, ref($bar2) eq 'Bar';
231 ok 25, ref($bar->{b}[0]) eq 'Foo';
232 ok 26, ref($bar->{b}[1]) eq 'Foo';
233 ok 27, ref($bar2->{b}[0]) eq 'Foo';
234 ok 28, ref($bar2->{b}[1]) eq 'Foo';