Remove duplicately applied patch shards.
[p5sagit/p5-mst-13.2.git] / t / lib / st-blessed.t
1 #!./perl
2
3 # $Id: blessed.t,v 0.7 2000/08/03 22:04:44 ram Exp $
4 #
5 #  Copyright (c) 1995-2000, Raphael Manfredi
6 #  
7 #  You may redistribute only under the terms of the Artistic License,
8 #  as specified in the README file that comes with the distribution.
9 #
10 # $Log: blessed.t,v $
11 # Revision 0.7  2000/08/03 22:04:44  ram
12 # Baseline for second beta release.
13 #
14
15 sub BEGIN {
16     chdir('t') if -d 't';
17     unshift @INC, '../lib';
18     require Config; import Config;
19     if ($Config{'extensions'} !~ /\bStorable\b/) {
20         print "1..0 # Skip: Storable was not built\n";
21         exit 0;
22     }
23     require 'lib/st-dump.pl';
24 }
25
26 sub ok;
27
28 use Storable qw(freeze thaw);
29
30 print "1..10\n";
31
32 package SHORT_NAME;
33
34 sub make { bless [], shift }
35
36 package SHORT_NAME_WITH_HOOK;
37
38 sub make { bless [], shift }
39
40 sub STORABLE_freeze {
41         my $self = shift;
42         return ("", $self);
43 }
44
45 sub STORABLE_thaw {
46         my $self = shift;
47         my $cloning = shift;
48         my ($x, $obj) = @_;
49         die "STORABLE_thaw" unless $obj eq $self;
50 }
51
52 package main;
53
54 # Still less than 256 bytes, so long classname logic not fully exercised
55 # Wait until Perl removes the restriction on identifier lengths.
56 my $name = "LONG_NAME_" . 'xxxxxxxxxxxxx::' x 14 . "final";
57
58 eval <<EOC;
59 package $name;
60
61 \@ISA = ("SHORT_NAME");
62 EOC
63 die $@ if $@;
64 ok 1, $@ eq '';
65
66 eval <<EOC;
67 package ${name}_WITH_HOOK;
68
69 \@ISA = ("SHORT_NAME_WITH_HOOK");
70 EOC
71 ok 2, $@ eq '';
72
73 # Construct a pool of objects
74 my @pool;
75
76 for (my $i = 0; $i < 10; $i++) {
77         push(@pool, SHORT_NAME->make);
78         push(@pool, SHORT_NAME_WITH_HOOK->make);
79         push(@pool, $name->make);
80         push(@pool, "${name}_WITH_HOOK"->make);
81 }
82
83 my $x = freeze \@pool;
84 ok 3, 1;
85
86 my $y = thaw $x;
87 ok 4, ref $y eq 'ARRAY';
88 ok 5, @{$y} == @pool;
89
90 ok 6, ref $y->[0] eq 'SHORT_NAME';
91 ok 7, ref $y->[1] eq 'SHORT_NAME_WITH_HOOK';
92 ok 8, ref $y->[2] eq $name;
93 ok 9, ref $y->[3] eq "${name}_WITH_HOOK";
94
95 my $good = 1;
96 for (my $i = 0; $i < 10; $i++) {
97         do { $good = 0; last } unless ref $y->[4*$i]   eq 'SHORT_NAME';
98         do { $good = 0; last } unless ref $y->[4*$i+1] eq 'SHORT_NAME_WITH_HOOK';
99         do { $good = 0; last } unless ref $y->[4*$i+2] eq $name;
100         do { $good = 0; last } unless ref $y->[4*$i+3] eq "${name}_WITH_HOOK";
101 }
102 ok 10, $good;
103