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