This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Uncomment and fix up tests at the end of Storable's blessed.t
[perl5.git] / dist / Storable / t / make_56_interwork.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 use Config;
5 use Storable qw(freeze thaw);
6
7 # Lilliput decreed that eggs should be eaten small end first.
8 # Belfuscu welcomed the rebels who wanted to eat big end first.
9 my $kingdom = $Config{byteorder} =~ /23/ ? "Lillput" : "Belfuscu";
10
11 my $frozen = freeze
12   ["This file was written with $Storable::VERSION on perl $]",
13    "$kingdom was correct", (~0 ^ (~0 >> 1) ^ 2),
14    "The End"];
15
16 my $ivsize = $Config{ivsize} || $Config{longsize};
17
18 my $storesize = unpack 'xxC', $frozen;
19 my $storebyteorder = unpack "xxxA$storesize", $frozen;
20
21 if ($Config{byteorder} eq $storebyteorder) {
22   my $ivtype = $Config{ivtype} || 'long';
23   print <<"EOM";
24 You only need to run this generator program where Config.pm's byteorder string
25 is not the same length as the size of IVs.
26
27 This length difference should only happen on perl 5.6.x configured with IVs as
28 long long on Unix, OS/2 or any platform that runs the Configure stript (ie not
29 MS Windows)
30
31 This is perl $], sizeof(long) is $Config{longsize}, IVs are '$ivtype', sizeof(IV) is $ivsize,
32 byteorder is '$Config{byteorder}', Storable $Storable::VERSION writes a byteorder of '$storebyteorder'
33 EOM
34   exit; # Grr '
35 }
36
37 my ($i, $l, $p, $n) = unpack "xxxx${storesize}CCCC", $frozen;
38
39 print <<"EOM";
40 # byteorder      '$storebyteorder'
41 # sizeof(int)    $i
42 # sizeof(long)   $l
43 # sizeof(char *) $p
44 # sizeof(NV)     $n
45 EOM
46
47 my $uu = pack 'u', $frozen;
48
49 printf "begin %3o $kingdom,$i,$l,$p,$n\n", ord 'A';
50 print $uu;
51 print "\nend\n\n";