Integrate perlio:
[p5sagit/p5-mst-13.2.git] / t / lib / st-overload.t
index cb6a83e..6d1e581 100644 (file)
@@ -1,20 +1,24 @@
 #!./perl
 
-# $Id: overload.t,v 0.7.1.1 2000/08/13 20:10:10 ram Exp $
+# $Id: overload.t,v 1.0.1.1 2001/02/17 12:27:22 ram Exp $
 #
 #  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: overload.t,v $
-# Revision 0.7.1.1  2000/08/13 20:10:10  ram
-# patch1: created
+# Revision 1.0.1.1  2001/02/17 12:27:22  ram
+# patch8: added test for structures with indirect ref to overloaded
+#
+# 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 +31,7 @@ sub ok;
 
 use Storable qw(freeze thaw);
 
-print "1..7\n";
+print "1..12\n";
 
 package OVERLOADED;
 
@@ -52,3 +56,42 @@ ok 6, "$d->[0]" eq "77";
 $d->[0][0]++;
 ok 7, "$d->[1]" eq "78";
 
+package REF_TO_OVER;
+
+sub make {
+       my $self = bless {}, shift;
+       my ($over) = @_;
+       $self->{over} = $over;
+       return $self;
+}
+
+package OVER;
+
+use overload
+       '+'             => \&plus,
+       '""'    => sub { ref $_[0] };
+
+sub plus {
+       return 314;
+}
+
+sub make {
+       my $self = bless {}, shift;
+       my $ref = REF_TO_OVER->make($self);
+       $self->{ref} = $ref;
+       return $self;
+}
+
+package main;
+
+$a = OVER->make();
+$b = thaw freeze $a;
+
+ok 8, ref $b eq 'OVER';
+ok 9, $a + $a == 314;
+ok 10, ref $b->{ref} eq 'REF_TO_OVER';
+ok 11, "$b->{ref}->{over}" eq "$b";
+ok 12, $b + $b == 314;
+
+1;
+