1N/A#!./perl
1N/A#
1N/A# Copyright (c) 1995-2000, Raphael Manfredi
1N/A#
1N/A# You may redistribute only under the same terms as Perl 5, as specified
1N/A# in the README file that comes with the distribution.
1N/A#
1N/A
1N/ABEGIN {
1N/A if ($ENV{PERL_CORE}){
1N/A chdir('t') if -d 't';
1N/A @INC = ('.', '../lib', '../ext/Storable/t');
1N/A } else {
1N/A unshift @INC, 't';
1N/A }
1N/A require Config; import Config;
1N/A if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
1N/A print "1..0 # Skip: Storable was not built\n";
1N/A exit 0;
1N/A }
1N/A require 'st-dump.pl';
1N/A}
1N/A
1N/Asub ok;
1N/A
1N/Aprint "1..8\n";
1N/A
1N/Ause Storable qw(freeze nfreeze thaw);
1N/A
1N/Apackage TIED_HASH;
1N/A
1N/Asub TIEHASH {
1N/A my $self = bless {}, shift;
1N/A return $self;
1N/A}
1N/A
1N/Asub FETCH {
1N/A my $self = shift;
1N/A my ($key) = @_;
1N/A $main::hash_fetch++;
1N/A return $self->{$key};
1N/A}
1N/A
1N/Asub STORE {
1N/A my $self = shift;
1N/A my ($key, $val) = @_;
1N/A $self->{$key} = $val;
1N/A}
1N/A
1N/Apackage SIMPLE;
1N/A
1N/Asub make {
1N/A my $self = bless [], shift;
1N/A my ($x) = @_;
1N/A $self->[0] = $x;
1N/A return $self;
1N/A}
1N/A
1N/Apackage ROOT;
1N/A
1N/Asub make {
1N/A my $self = bless {}, shift;
1N/A my $h = tie %hash, TIED_HASH;
1N/A $self->{h} = $h;
1N/A $self->{ref} = \%hash;
1N/A my @pool;
1N/A for (my $i = 0; $i < 5; $i++) {
1N/A push(@pool, SIMPLE->make($i));
1N/A }
1N/A $self->{obj} = \@pool;
1N/A my @a = ('string', $h, $self);
1N/A $self->{a} = \@a;
1N/A $self->{num} = [1, 0, -3, -3.14159, 456, 4.5];
1N/A $h->{key1} = 'val1';
1N/A $h->{key2} = 'val2';
1N/A return $self;
1N/A};
1N/A
1N/Asub num { $_[0]->{num} }
1N/Asub h { $_[0]->{h} }
1N/Asub ref { $_[0]->{ref} }
1N/Asub obj { $_[0]->{obj} }
1N/A
1N/Apackage main;
1N/A
1N/Amy $is_EBCDIC = (ord('A') == 193) ? 1 : 0;
1N/A
1N/Amy $r = ROOT->make;
1N/A
1N/Amy $data = '';
1N/Aif (!$is_EBCDIC) { # ASCII machine
1N/A while (<DATA>) {
1N/A next if /^#/;
1N/A $data .= unpack("u", $_);
1N/A }
1N/A} else {
1N/A while (<DATA>) {
1N/A next if /^#$/; # skip comments
1N/A next if /^#\s+/; # skip comments
1N/A next if /^[^#]/; # skip uuencoding for ASCII machines
1N/A s/^#//; # prepare uuencoded data for EBCDIC machines
1N/A $data .= unpack("u", $_);
1N/A }
1N/A}
1N/A
1N/Amy $expected_length = $is_EBCDIC ? 217 : 278;
1N/Aok 1, length $data == $expected_length;
1N/A
1N/Amy $y = thaw($data);
1N/Aok 2, 1;
1N/Aok 3, ref $y eq 'ROOT';
1N/A
1N/A$Storable::canonical = 1; # Prevent "used once" warning
1N/A$Storable::canonical = 1;
1N/A# Allow for long double string conversions.
1N/A$y->{num}->[3] += 0;
1N/A$r->{num}->[3] += 0;
1N/Aok 4, nfreeze($y) eq nfreeze($r);
1N/A
1N/Aok 5, $y->ref->{key1} eq 'val1';
1N/Aok 6, $y->ref->{key2} eq 'val2';
1N/Aok 7, $hash_fetch == 2;
1N/A
1N/Amy $num = $r->num;
1N/Amy $ok = 1;
1N/Afor (my $i = 0; $i < @$num; $i++) {
1N/A do { $ok = 0; last } unless $num->[$i] == $y->num->[$i];
1N/A}
1N/Aok 8, $ok;
1N/A
1N/A__END__
1N/A#
1N/A# using Storable-0.6@11, output of: print pack("u", nfreeze(ROOT->make));
1N/A# original size: 278 bytes
1N/A#
1N/AM`P,````%!`(````&"(%8"(!8"'U8"@@M,RXQ-#$U.5@)```!R%@*`S0N-5A8
1N/AM6`````-N=6T$`P````(*!'9A;#%8````!&ME>3$*!'9A;#)8````!&ME>3)B
1N/AM"51)141?2$%32%A8`````6@$`@````,*!G-T<FEN9U@$``````I8!```````
1N/AM6%A8`````6$$`@````4$`@````$(@%AB!E-)35!,15A8!`(````!"(%88@93
1N/AM24U03$586`0"`````0B"6&(&4TE-4$Q%6%@$`@````$(@UAB!E-)35!,15A8
1N/AM!`(````!"(188@9324U03$586%A8`````V]B:@0,!``````*6%A8`````W)E
1N/A(9F($4D]/5%@`
1N/A#
1N/A# using Storable-0.6@11, output of: print '#' . pack("u", nfreeze(ROOT->make));
1N/A# on OS/390 (cp 1047) original size: 217 bytes
1N/A#
1N/A#M!0,1!-G6UN,#````!00,!!$)X\G%Q&W(P>+(`P````(*!*6!D_$````$DH6H
1N/A#M\0H$I8&3\@````22A:CR`````YF%A@0"````!@B!"(`(?0H(8/-+\?3Q]?D)
1N/A#M```!R`H#]$OU`````Y6DE`0"````!001!N+)U-?3Q0(````!"(`$$@("````
1N/A#M`0B!!!("`@````$(@@02`@(````!"(,$$@("`````0B$`````Y:"D00`````
1N/A#E!`````&(!`(````#"@:BHYF)E8<$``````0$```````````!@0``