Overeager visited-positions optimizations
[p5sagit/p5-mst-13.2.git] / t / lib / st-recurse.t
index ebaeba7..b429747 100644 (file)
@@ -1,20 +1,29 @@
 #!./perl
 
-# $Id: recurse.t,v 0.7 2000/08/03 22:04:45 ram Exp $
+# $Id: recurse.t,v 1.0.1.2 2000/11/05 17:22:05 ram Exp ram $
 #
 #  Copyright (c) 1995-2000, Raphael Manfredi
 #  
-#  You may redistribute only under the terms of the Artistic License,
-#  as specified in the README file that comes with the distribution.
+#  You may redistribute only under the same terms as Perl 5, as specified
+#  in the README file that comes with the distribution.
 #  
 # $Log: recurse.t,v $
-# Revision 0.7  2000/08/03 22:04:45  ram
-# Baseline for second beta release.
+# Revision 1.0.1.2  2000/11/05 17:22:05  ram
+# patch6: stress hook a little more with refs to lexicals
+#
+# $Log: recurse.t,v $
+# Revision 1.0.1.1  2000/09/17 16:48:05  ram
+# patch1: added test case for store hook bug
+#
+# $Log: recurse.t,v $
+# Revision 1.0  2000/09/01 19:40:42  ram
+# Baseline for first official release.
 #
 
 sub BEGIN {
     chdir('t') if -d 't';
-    unshift @INC, '../lib';
+    @INC = '.'; 
+    push @INC, '../lib';
     require Config; import Config;
     if ($Config{'extensions'} !~ /\bStorable\b/) {
         print "1..0 # Skip: Storable was not built\n";
@@ -27,7 +36,7 @@ sub ok;
 
 use Storable qw(freeze thaw dclone);
 
-print "1..23\n";
+print "1..28\n";
 
 package OBJ_REAL;
 
@@ -92,15 +101,19 @@ sub make {
 
 sub STORABLE_freeze {
        my $self = shift;
-       my $t = dclone($self->{sync});
-       return ("", [$t, $self->{ext}], $self, $self->{ext});
+       my %copy = %$self;
+       my $r = \%copy;
+       my $t = dclone($r->{sync});
+       return ("", [$t, $self->{ext}], $r, $self, $r->{ext});
 }
 
 sub STORABLE_thaw {
        my $self = shift;
-       my ($cloning, $undef, $a, $obj, $ext) = @_;
+       my ($cloning, $undef, $a, $r, $obj, $ext) = @_;
        die "STORABLE_thaw #1" unless $obj eq $self;
        die "STORABLE_thaw #2" unless ref $a eq 'ARRAY';
+       die "STORABLE_thaw #3" unless ref $r eq 'HASH';
+       die "STORABLE_thaw #4" unless $a->[1] == $r->{ext};
        $self->{ok} = $self;
        ($self->{sync}, $self->{ext}) = @$a;
 }
@@ -180,3 +193,51 @@ ok 21, $OBJ_REAL2::hook_called == 2 * $OBJ_REAL2::MAX;
 
 ok 22, !Storable::is_storing;
 ok 23, !Storable::is_retrieving;
+
+#
+# The following was a test-case that Salvador Ortiz Garcia <sog@msg.com.mx>
+# sent me, along with a proposed fix.
+#
+
+package Foo;
+
+sub new {
+       my $class = shift;
+       my $dat = shift;
+       return bless {dat => $dat}, $class;
+}
+
+package Bar;
+sub new {
+       my $class = shift;
+       return bless {
+               a => 'dummy',
+               b => [ 
+                       Foo->new(1),
+                       Foo->new(2), # Second instance of a Foo 
+               ]
+       }, $class;
+}
+
+sub STORABLE_freeze {
+       my($self,$clonning) = @_;
+       return "$self->{a}", $self->{b};
+}
+
+sub STORABLE_thaw {
+       my($self,$clonning,$dummy,$o) = @_;
+       $self->{a} = $dummy;
+       $self->{b} = $o;
+}
+
+package main;
+
+my $bar = new Bar;
+my $bar2 = thaw freeze $bar;
+
+ok 24, ref($bar2) eq 'Bar';
+ok 25, ref($bar->{b}[0]) eq 'Foo';
+ok 26, ref($bar->{b}[1]) eq 'Foo';
+ok 27, ref($bar2->{b}[0]) eq 'Foo';
+ok 28, ref($bar2->{b}[1]) eq 'Foo';
+