1 #!/usr/local/bin/perl -w
5 use Hash::Util qw(lock_hash unlock_hash lock_keys);
6 use Storable qw(nfreeze);
8 # If this looks like a hack, it's probably because it is :-)
10 my ($data, $name) = @_;
11 my $frozen = nfreeze $data;
13 my $uu = pack 'u', $frozen;
15 printf "begin %3o $name\n", ord 'A';
21 my %hash = (perl=>"rules");
25 uuencode_it (\%hash, "Locked hash");
29 lock_keys %hash, 'perl', 'rules';
32 uuencode_it (\%hash, "Locked hash placeholder");
36 lock_keys %hash, 'perl';
38 uuencode_it (\%hash, "Locked keys");
42 lock_keys %hash, 'perl', 'rules';
44 uuencode_it (\%hash, "Locked keys placeholder");
48 my $utf8 = "\x{DF}\x{100}";
51 uuencode_it (\$utf8, "Short 8 bit utf8 data");
54 utf8::encode ($utf8b);
56 uuencode_it (\$utf8b, "Short 8 bit utf8 data as bytes");
60 uuencode_it (\$utf8, "Long 8 bit utf8 data");
64 uuencode_it (\$utf8, "Short 24 bit utf8 data");
67 utf8::encode ($utf8b);
69 uuencode_it (\$utf8b, "Short 24 bit utf8 data as bytes");
73 uuencode_it (\$utf8, "Long 24 bit utf8 data");
75 # Hash which has the utf8 bit set, but no longer has any utf8 keys
76 my %uhash = ("\x{100}", "gone", "perl", "rules");
77 delete $uhash{"\x{100}"};
79 # use Devel::Peek; Dump \%uhash;
80 uuencode_it (\%uhash, "Hash with utf8 flag but no utf8 keys");
82 $utf8 = "Schlo\xdf" . chr 256;
84 my $a_circumflex = (ord ('A') == 193 ? "\x47" : "\xe5");
85 %uhash = (map {$_, $_} 'castle', "ch${a_circumflex}teau", $utf8, "\x{57CE}");
87 uuencode_it (\%uhash, "Hash with utf8 keys");
91 uuencode_it (\%uhash, "Locked hash with utf8 keys");
95 while (my ($key, $val) = each %uhash) {
96 # hash keys are always stored downgraded to bytes if possible, with a flag
97 # to say "promote back to utf8"
98 # Whereas scalars are stored as is.
99 utf8::encode ($key) if ord $key > 256;
101 utf8::encode ($val) unless $val eq "ch\xe5teau";
105 uuencode_it (\%pre56, "Hash with utf8 keys for pre 5.6");
106 uuencode_it (\%pre58, "Hash with utf8 keys for 5.6");