[PATCH] Re: Storable 2.0.0 fails on vendor perl on Mac OS X 10.1
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / blessed.t
CommitLineData
7a6a85bf 1#!./perl
2
9e21b3d0 3# $Id: blessed.t,v 1.0 2000/09/01 19:40:41 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: blessed.t,v $
9e21b3d0 11# Revision 1.0 2000/09/01 19:40:41 ram
12# Baseline for first official release.
7a6a85bf 13#
14
15sub BEGIN {
0c384302 16 if ($ENV{PERL_CORE}){
17 chdir('t') if -d 't';
7dadce44 18 @INC = ('.', '../lib', '../ext/Storable/t');
372cb964 19 } else {
20 unshift @INC, 't';
0c384302 21 }
9f233367 22 require Config; import Config;
0c384302 23 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 24 print "1..0 # Skip: Storable was not built\n";
25 exit 0;
26 }
372cb964 27 require 'st-dump.pl';
7a6a85bf 28}
29
30sub ok;
31
32use Storable qw(freeze thaw);
33
34print "1..10\n";
35
36package SHORT_NAME;
37
38sub make { bless [], shift }
39
40package SHORT_NAME_WITH_HOOK;
41
42sub make { bless [], shift }
43
44sub STORABLE_freeze {
45 my $self = shift;
46 return ("", $self);
47}
48
49sub STORABLE_thaw {
50 my $self = shift;
51 my $cloning = shift;
52 my ($x, $obj) = @_;
53 die "STORABLE_thaw" unless $obj eq $self;
54}
55
56package main;
57
58# Still less than 256 bytes, so long classname logic not fully exercised
59# Wait until Perl removes the restriction on identifier lengths.
60my $name = "LONG_NAME_" . 'xxxxxxxxxxxxx::' x 14 . "final";
61
62eval <<EOC;
63package $name;
64
65\@ISA = ("SHORT_NAME");
66EOC
67die $@ if $@;
68ok 1, $@ eq '';
69
70eval <<EOC;
71package ${name}_WITH_HOOK;
72
73\@ISA = ("SHORT_NAME_WITH_HOOK");
74EOC
75ok 2, $@ eq '';
76
77# Construct a pool of objects
78my @pool;
79
80for (my $i = 0; $i < 10; $i++) {
81 push(@pool, SHORT_NAME->make);
82 push(@pool, SHORT_NAME_WITH_HOOK->make);
83 push(@pool, $name->make);
84 push(@pool, "${name}_WITH_HOOK"->make);
85}
86
87my $x = freeze \@pool;
88ok 3, 1;
89
90my $y = thaw $x;
91ok 4, ref $y eq 'ARRAY';
92ok 5, @{$y} == @pool;
93
94ok 6, ref $y->[0] eq 'SHORT_NAME';
95ok 7, ref $y->[1] eq 'SHORT_NAME_WITH_HOOK';
96ok 8, ref $y->[2] eq $name;
97ok 9, ref $y->[3] eq "${name}_WITH_HOOK";
98
99my $good = 1;
100for (my $i = 0; $i < 10; $i++) {
101 do { $good = 0; last } unless ref $y->[4*$i] eq 'SHORT_NAME';
102 do { $good = 0; last } unless ref $y->[4*$i+1] eq 'SHORT_NAME_WITH_HOOK';
103 do { $good = 0; last } unless ref $y->[4*$i+2] eq $name;
104 do { $good = 0; last } unless ref $y->[4*$i+3] eq "${name}_WITH_HOOK";
105}
106ok 10, $good;
107