Few more casts, need reported in
[p5sagit/p5-mst-13.2.git] / t / lib / st-blessed.t
CommitLineData
7a6a85bf 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
15sub BEGIN {
16 chdir('t') if -d 't';
17 unshift @INC, '../lib';
18 require 'lib/st-dump.pl';
19}
20
21sub ok;
22
23use Storable qw(freeze thaw);
24
25print "1..10\n";
26
27package SHORT_NAME;
28
29sub make { bless [], shift }
30
31package SHORT_NAME_WITH_HOOK;
32
33sub make { bless [], shift }
34
35sub STORABLE_freeze {
36 my $self = shift;
37 return ("", $self);
38}
39
40sub STORABLE_thaw {
41 my $self = shift;
42 my $cloning = shift;
43 my ($x, $obj) = @_;
44 die "STORABLE_thaw" unless $obj eq $self;
45}
46
47package main;
48
49# Still less than 256 bytes, so long classname logic not fully exercised
50# Wait until Perl removes the restriction on identifier lengths.
51my $name = "LONG_NAME_" . 'xxxxxxxxxxxxx::' x 14 . "final";
52
53eval <<EOC;
54package $name;
55
56\@ISA = ("SHORT_NAME");
57EOC
58die $@ if $@;
59ok 1, $@ eq '';
60
61eval <<EOC;
62package ${name}_WITH_HOOK;
63
64\@ISA = ("SHORT_NAME_WITH_HOOK");
65EOC
66ok 2, $@ eq '';
67
68# Construct a pool of objects
69my @pool;
70
71for (my $i = 0; $i < 10; $i++) {
72 push(@pool, SHORT_NAME->make);
73 push(@pool, SHORT_NAME_WITH_HOOK->make);
74 push(@pool, $name->make);
75 push(@pool, "${name}_WITH_HOOK"->make);
76}
77
78my $x = freeze \@pool;
79ok 3, 1;
80
81my $y = thaw $x;
82ok 4, ref $y eq 'ARRAY';
83ok 5, @{$y} == @pool;
84
85ok 6, ref $y->[0] eq 'SHORT_NAME';
86ok 7, ref $y->[1] eq 'SHORT_NAME_WITH_HOOK';
87ok 8, ref $y->[2] eq $name;
88ok 9, ref $y->[3] eq "${name}_WITH_HOOK";
89
90my $good = 1;
91for (my $i = 0; $i < 10; $i++) {
92 do { $good = 0; last } unless ref $y->[4*$i] eq 'SHORT_NAME';
93 do { $good = 0; last } unless ref $y->[4*$i+1] eq 'SHORT_NAME_WITH_HOOK';
94 do { $good = 0; last } unless ref $y->[4*$i+2] eq $name;
95 do { $good = 0; last } unless ref $y->[4*$i+3] eq "${name}_WITH_HOOK";
96}
97ok 10, $good;
98