Re: files not cleaned even by veryclean
[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';
8268a68b 17 unshift @INC, '../lib';
9f233367 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 }
7a6a85bf 23 require 'lib/st-dump.pl';
24}
25
26sub ok;
27
28use Storable qw(freeze thaw);
29
30print "1..10\n";
31
32package SHORT_NAME;
33
34sub make { bless [], shift }
35
36package SHORT_NAME_WITH_HOOK;
37
38sub make { bless [], shift }
39
40sub STORABLE_freeze {
41 my $self = shift;
42 return ("", $self);
43}
44
45sub STORABLE_thaw {
46 my $self = shift;
47 my $cloning = shift;
48 my ($x, $obj) = @_;
49 die "STORABLE_thaw" unless $obj eq $self;
50}
51
52package 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.
56my $name = "LONG_NAME_" . 'xxxxxxxxxxxxx::' x 14 . "final";
57
58eval <<EOC;
59package $name;
60
61\@ISA = ("SHORT_NAME");
62EOC
63die $@ if $@;
64ok 1, $@ eq '';
65
66eval <<EOC;
67package ${name}_WITH_HOOK;
68
69\@ISA = ("SHORT_NAME_WITH_HOOK");
70EOC
71ok 2, $@ eq '';
72
73# Construct a pool of objects
74my @pool;
75
76for (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
83my $x = freeze \@pool;
84ok 3, 1;
85
86my $y = thaw $x;
87ok 4, ref $y eq 'ARRAY';
88ok 5, @{$y} == @pool;
89
90ok 6, ref $y->[0] eq 'SHORT_NAME';
91ok 7, ref $y->[1] eq 'SHORT_NAME_WITH_HOOK';
92ok 8, ref $y->[2] eq $name;
93ok 9, ref $y->[3] eq "${name}_WITH_HOOK";
94
95my $good = 1;
96for (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}
102ok 10, $good;
103