test appears to be ass_u_ming sizeof(long) == sizeof(IV), which
[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';
21 @INC = '.';
22 push @INC, '../lib';
23 }
9f233367 24 require Config; import Config;
0c384302 25 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 26 print "1..0 # Skip: Storable was not built\n";
27 exit 0;
28 }
7a6a85bf 29 require 'lib/st-dump.pl';
30}
31
32sub ok;
33
34use Storable qw(freeze thaw);
35
b12202d0 36print "1..12\n";
7a6a85bf 37
38package OVERLOADED;
39
40use overload
41 '""' => sub { $_[0][0] };
42
43package main;
44
45$a = bless [77], OVERLOADED;
46
47$b = thaw freeze $a;
48ok 1, ref $b eq 'OVERLOADED';
49ok 2, "$b" eq "77";
50
51$c = thaw freeze \$a;
52ok 3, ref $c eq 'REF';
53ok 4, ref $$c eq 'OVERLOADED';
54ok 5, "$$c" eq "77";
55
56$d = thaw freeze [$a, $a];
57ok 6, "$d->[0]" eq "77";
58$d->[0][0]++;
59ok 7, "$d->[1]" eq "78";
60
b12202d0 61package REF_TO_OVER;
62
63sub make {
64 my $self = bless {}, shift;
65 my ($over) = @_;
66 $self->{over} = $over;
67 return $self;
68}
69
70package OVER;
71
72use overload
73 '+' => \&plus,
74 '""' => sub { ref $_[0] };
75
76sub plus {
77 return 314;
78}
79
80sub make {
81 my $self = bless {}, shift;
82 my $ref = REF_TO_OVER->make($self);
83 $self->{ref} = $ref;
84 return $self;
85}
86
87package main;
88
89$a = OVER->make();
90$b = thaw freeze $a;
91
92ok 8, ref $b eq 'OVER';
93ok 9, $a + $a == 314;
94ok 10, ref $b->{ref} eq 'REF_TO_OVER';
95ok 11, "$b->{ref}->{over}" eq "$b";
96ok 12, $b + $b == 314;
97
981;
99