Re: [Another bug] Re: about Storable perl module (again)
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / overload.t
CommitLineData
7a6a85bf 1#!./perl
2
b12202d0 3# $Id: overload.t,v 1.0.1.1 2001/02/17 12:27:22 ram Exp $
7a6a85bf 4#
5# Copyright (c) 1995-2000, Raphael Manfredi
6#
9e21b3d0 7# You may redistribute only under the same terms as Perl 5, as specified
8# in the README file that comes with the distribution.
7a6a85bf 9#
10# $Log: overload.t,v $
b12202d0 11# Revision 1.0.1.1 2001/02/17 12:27:22 ram
12# patch8: added test for structures with indirect ref to overloaded
13#
9e21b3d0 14# Revision 1.0 2000/09/01 19:40:42 ram
15# Baseline for first official release.
7a6a85bf 16#
17
18sub BEGIN {
0c384302 19 if ($ENV{PERL_CORE}){
20 chdir('t') if -d 't';
7dadce44 21 @INC = ('.', '../lib', '../ext/Storable/t');
372cb964 22 } else {
23 unshift @INC, 't';
0c384302 24 }
9f233367 25 require Config; import Config;
0c384302 26 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 27 print "1..0 # Skip: Storable was not built\n";
28 exit 0;
29 }
372cb964 30 require 'st-dump.pl';
7a6a85bf 31}
32
33sub ok;
34
35use Storable qw(freeze thaw);
36
b12202d0 37print "1..12\n";
7a6a85bf 38
39package OVERLOADED;
40
41use overload
42 '""' => sub { $_[0][0] };
43
44package main;
45
46$a = bless [77], OVERLOADED;
47
48$b = thaw freeze $a;
49ok 1, ref $b eq 'OVERLOADED';
50ok 2, "$b" eq "77";
51
52$c = thaw freeze \$a;
53ok 3, ref $c eq 'REF';
54ok 4, ref $$c eq 'OVERLOADED';
55ok 5, "$$c" eq "77";
56
57$d = thaw freeze [$a, $a];
58ok 6, "$d->[0]" eq "77";
59$d->[0][0]++;
60ok 7, "$d->[1]" eq "78";
61
b12202d0 62package REF_TO_OVER;
63
64sub make {
65 my $self = bless {}, shift;
66 my ($over) = @_;
67 $self->{over} = $over;
68 return $self;
69}
70
71package OVER;
72
73use overload
74 '+' => \&plus,
75 '""' => sub { ref $_[0] };
76
77sub plus {
78 return 314;
79}
80
81sub make {
82 my $self = bless {}, shift;
83 my $ref = REF_TO_OVER->make($self);
84 $self->{ref} = $ref;
85 return $self;
86}
87
88package main;
89
90$a = OVER->make();
91$b = thaw freeze $a;
92
93ok 8, ref $b eq 'OVER';
94ok 9, $a + $a == 314;
95ok 10, ref $b->{ref} eq 'REF_TO_OVER';
96ok 11, "$b->{ref}->{over}" eq "$b";
97ok 12, $b + $b == 314;
98
991;
100