Commit | Line | Data |
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 | # |
7a6a85bf |
10 | |
11 | sub BEGIN { |
0c384302 |
12 | if ($ENV{PERL_CORE}){ |
13 | chdir('t') if -d 't'; |
7dadce44 |
14 | @INC = ('.', '../lib', '../ext/Storable/t'); |
372cb964 |
15 | } else { |
16 | unshift @INC, 't'; |
0c384302 |
17 | } |
9f233367 |
18 | require Config; import Config; |
0c384302 |
19 | if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) { |
9f233367 |
20 | print "1..0 # Skip: Storable was not built\n"; |
21 | exit 0; |
22 | } |
372cb964 |
23 | require 'st-dump.pl'; |
7a6a85bf |
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; |