This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump Devel::PPPort in Changes file
[perl5.git] / dist / Storable / __Storable__.pm
1 #
2 #  Copyright (c) 1995-2001, Raphael Manfredi
3 #  Copyright (c) 2002-2014 by the Perl 5 Porters
4 #  Copyright (c) 2015-2016 cPanel Inc
5 #  Copyright (c) 2017 Reini Urban
6 #
7 #  You may redistribute only under the same terms as Perl 5, as specified
8 #  in the README file that comes with the distribution.
9 #
10
11 require XSLoader;
12 require Exporter;
13 package Storable;
14
15 our @ISA = qw(Exporter);
16 our @EXPORT = qw(store retrieve);
17 our @EXPORT_OK = qw(
18         nstore store_fd nstore_fd fd_retrieve
19         freeze nfreeze thaw
20         dclone
21         retrieve_fd
22         lock_store lock_nstore lock_retrieve
23         file_magic read_magic
24         BLESS_OK TIE_OK FLAGS_COMPAT
25         stack_depth stack_depth_hash
26 );
27
28 our ($canonical, $forgive_me);
29
30 our $VERSION = '3.13';
31
32 our $recursion_limit;
33 our $recursion_limit_hash;
34
35 do "Storable/Limit.pm";
36
37 $recursion_limit = 512
38   unless defined $recursion_limit;
39 $recursion_limit_hash = 256
40   unless defined $recursion_limit_hash;
41
42 use Carp;
43
44 BEGIN {
45     if (eval {
46         local $SIG{__DIE__};
47         local @INC = @INC;
48         pop @INC if $INC[-1] eq '.';
49         require Log::Agent;
50         1;
51     }) {
52         Log::Agent->import;
53     }
54     #
55     # Use of Log::Agent is optional. If it hasn't imported these subs then
56     # provide a fallback implementation.
57     #
58     unless ($Storable::{logcroak} && *{$Storable::{logcroak}}{CODE}) {
59         *logcroak = \&Carp::croak;
60     }
61     else {
62         # Log::Agent's logcroak always adds a newline to the error it is
63         # given.  This breaks refs getting thrown.  We can just discard what
64         # it throws (but keep whatever logging it does) and throw the original
65         # args.
66         no warnings 'redefine';
67         my $logcroak = \&logcroak;
68         *logcroak = sub {
69             my @args = @_;
70             eval { &$logcroak };
71             Carp::croak(@args);
72         };
73     }
74     unless ($Storable::{logcarp} && *{$Storable::{logcarp}}{CODE}) {
75         *logcarp = \&Carp::carp;
76     }
77 }
78
79 #
80 # They might miss :flock in Fcntl
81 #
82
83 BEGIN {
84     if (eval { require Fcntl; 1 } && exists $Fcntl::EXPORT_TAGS{'flock'}) {
85         Fcntl->import(':flock');
86     } else {
87         eval q{
88                   sub LOCK_SH () { 1 }
89                   sub LOCK_EX () { 2 }
90               };
91     }
92 }
93
94 sub CLONE {
95     # clone context under threads
96     Storable::init_perinterp();
97 }
98
99 sub BLESS_OK     () { 2 }
100 sub TIE_OK       () { 4 }
101 sub FLAGS_COMPAT () { BLESS_OK | TIE_OK }
102
103 # By default restricted hashes are downgraded on earlier perls.
104
105 $Storable::flags = FLAGS_COMPAT;
106 $Storable::downgrade_restricted = 1;
107 $Storable::accept_future_minor = 1;
108
109 XSLoader::load('Storable');
110
111 #
112 # Determine whether locking is possible, but only when needed.
113 #
114
115 sub CAN_FLOCK; # TEMPLATE - replaced by Storable.pm.PL
116
117 sub show_file_magic {
118     print <<EOM;
119 #
120 # To recognize the data files of the Perl module Storable,
121 # the following lines need to be added to the local magic(5) file,
122 # usually either /usr/share/misc/magic or /etc/magic.
123 #
124 0       string  perl-store      perl Storable(v0.6) data
125 >4      byte    >0      (net-order %d)
126 >>4     byte    &01     (network-ordered)
127 >>4     byte    =3      (major 1)
128 >>4     byte    =2      (major 1)
129
130 0       string  pst0    perl Storable(v0.7) data
131 >4      byte    >0
132 >>4     byte    &01     (network-ordered)
133 >>4     byte    =5      (major 2)
134 >>4     byte    =4      (major 2)
135 >>5     byte    >0      (minor %d)
136 EOM
137 }
138
139 sub file_magic {
140     require IO::File;
141
142     my $file = shift;
143     my $fh = IO::File->new;
144     open($fh, "<", $file) || die "Can't open '$file': $!";
145     binmode($fh);
146     defined(sysread($fh, my $buf, 32)) || die "Can't read from '$file': $!";
147     close($fh);
148
149     $file = "./$file" unless $file;  # ensure TRUE value
150
151     return read_magic($buf, $file);
152 }
153
154 sub read_magic {
155     my($buf, $file) = @_;
156     my %info;
157
158     my $buflen = length($buf);
159     my $magic;
160     if ($buf =~ s/^(pst0|perl-store)//) {
161         $magic = $1;
162         $info{file} = $file || 1;
163     }
164     else {
165         return undef if $file;
166         $magic = "";
167     }
168
169     return undef unless length($buf);
170
171     my $net_order;
172     if ($magic eq "perl-store" && ord(substr($buf, 0, 1)) > 1) {
173         $info{version} = -1;
174         $net_order = 0;
175     }
176     else {
177         $buf =~ s/(.)//s;
178         my $major = (ord $1) >> 1;
179         return undef if $major > 4; # sanity (assuming we never go that high)
180         $info{major} = $major;
181         $net_order = (ord $1) & 0x01;
182         if ($major > 1) {
183             return undef unless $buf =~ s/(.)//s;
184             my $minor = ord $1;
185             $info{minor} = $minor;
186             $info{version} = "$major.$minor";
187             $info{version_nv} = sprintf "%d.%03d", $major, $minor;
188         }
189         else {
190             $info{version} = $major;
191         }
192     }
193     $info{version_nv} ||= $info{version};
194     $info{netorder} = $net_order;
195
196     unless ($net_order) {
197         return undef unless $buf =~ s/(.)//s;
198         my $len = ord $1;
199         return undef unless length($buf) >= $len;
200         return undef unless $len == 4 || $len == 8;  # sanity
201         @info{qw(byteorder intsize longsize ptrsize)}
202             = unpack "a${len}CCC", $buf;
203         (substr $buf, 0, $len + 3) = '';
204         if ($info{version_nv} >= 2.002) {
205             return undef unless $buf =~ s/(.)//s;
206             $info{nvsize} = ord $1;
207         }
208     }
209     $info{hdrsize} = $buflen - length($buf);
210
211     return \%info;
212 }
213
214 sub BIN_VERSION_NV {
215     sprintf "%d.%03d", BIN_MAJOR(), BIN_MINOR();
216 }
217
218 sub BIN_WRITE_VERSION_NV {
219     sprintf "%d.%03d", BIN_MAJOR(), BIN_WRITE_MINOR();
220 }
221
222 #
223 # store
224 #
225 # Store target object hierarchy, identified by a reference to its root.
226 # The stored object tree may later be retrieved to memory via retrieve.
227 # Returns undef if an I/O error occurred, in which case the file is
228 # removed.
229 #
230 sub store {
231     return _store(\&pstore, @_, 0);
232 }
233
234 #
235 # nstore
236 #
237 # Same as store, but in network order.
238 #
239 sub nstore {
240     return _store(\&net_pstore, @_, 0);
241 }
242
243 #
244 # lock_store
245 #
246 # Same as store, but flock the file first (advisory locking).
247 #
248 sub lock_store {
249     return _store(\&pstore, @_, 1);
250 }
251
252 #
253 # lock_nstore
254 #
255 # Same as nstore, but flock the file first (advisory locking).
256 #
257 sub lock_nstore {
258     return _store(\&net_pstore, @_, 1);
259 }
260
261 # Internal store to file routine
262 sub _store {
263     my $xsptr = shift;
264     my $self = shift;
265     my ($file, $use_locking) = @_;
266     logcroak "not a reference" unless ref($self);
267     logcroak "wrong argument number" unless @_ == 2;    # No @foo in arglist
268     local *FILE;
269     if ($use_locking) {
270         open(FILE, ">>", $file) || logcroak "can't write into $file: $!";
271         unless (&CAN_FLOCK) {
272             logcarp
273               "Storable::lock_store: fcntl/flock emulation broken on $^O";
274             return undef;
275         }
276         flock(FILE, LOCK_EX) ||
277           logcroak "can't get exclusive lock on $file: $!";
278         truncate FILE, 0;
279         # Unlocking will happen when FILE is closed
280     } else {
281         open(FILE, ">", $file) || logcroak "can't create $file: $!";
282     }
283     binmode FILE;       # Archaic systems...
284     my $da = $@;        # Don't mess if called from exception handler
285     my $ret;
286     # Call C routine nstore or pstore, depending on network order
287     eval { $ret = &$xsptr(*FILE, $self) };
288     # close will return true on success, so the or short-circuits, the ()
289     # expression is true, and for that case the block will only be entered
290     # if $@ is true (ie eval failed)
291     # if close fails, it returns false, $ret is altered, *that* is (also)
292     # false, so the () expression is false, !() is true, and the block is
293     # entered.
294     if (!(close(FILE) or undef $ret) || $@) {
295         unlink($file) or warn "Can't unlink $file: $!\n";
296     }
297     if ($@) {
298         $@ =~ s/\.?\n$/,/ unless ref $@;
299         logcroak $@;
300     }
301     $@ = $da;
302     return $ret;
303 }
304
305 #
306 # store_fd
307 #
308 # Same as store, but perform on an already opened file descriptor instead.
309 # Returns undef if an I/O error occurred.
310 #
311 sub store_fd {
312     return _store_fd(\&pstore, @_);
313 }
314
315 #
316 # nstore_fd
317 #
318 # Same as store_fd, but in network order.
319 #
320 sub nstore_fd {
321     my ($self, $file) = @_;
322     return _store_fd(\&net_pstore, @_);
323 }
324
325 # Internal store routine on opened file descriptor
326 sub _store_fd {
327     my $xsptr = shift;
328     my $self = shift;
329     my ($file) = @_;
330     logcroak "not a reference" unless ref($self);
331     logcroak "too many arguments" unless @_ == 1;       # No @foo in arglist
332     my $fd = fileno($file);
333     logcroak "not a valid file descriptor" unless defined $fd;
334     my $da = $@;                # Don't mess if called from exception handler
335     my $ret;
336     # Call C routine nstore or pstore, depending on network order
337     eval { $ret = &$xsptr($file, $self) };
338     logcroak $@ if $@ =~ s/\.?\n$/,/;
339     local $\; print $file '';   # Autoflush the file if wanted
340     $@ = $da;
341     return $ret;
342 }
343
344 #
345 # freeze
346 #
347 # Store object and its hierarchy in memory and return a scalar
348 # containing the result.
349 #
350 sub freeze {
351     _freeze(\&mstore, @_);
352 }
353
354 #
355 # nfreeze
356 #
357 # Same as freeze but in network order.
358 #
359 sub nfreeze {
360     _freeze(\&net_mstore, @_);
361 }
362
363 # Internal freeze routine
364 sub _freeze {
365     my $xsptr = shift;
366     my $self = shift;
367     logcroak "not a reference" unless ref($self);
368     logcroak "too many arguments" unless @_ == 0;       # No @foo in arglist
369     my $da = $@;                # Don't mess if called from exception handler
370     my $ret;
371     # Call C routine mstore or net_mstore, depending on network order
372     eval { $ret = &$xsptr($self) };
373     if ($@) {
374         $@ =~ s/\.?\n$/,/ unless ref $@;
375         logcroak $@;
376     }
377     $@ = $da;
378     return $ret ? $ret : undef;
379 }
380
381 #
382 # retrieve
383 #
384 # Retrieve object hierarchy from disk, returning a reference to the root
385 # object of that tree.
386 #
387 # retrieve(file, flags)
388 # flags include by default BLESS_OK=2 | TIE_OK=4
389 # with flags=0 or the global $Storable::flags set to 0, no resulting object
390 # will be blessed nor tied.
391 #
392 sub retrieve {
393     _retrieve(shift, 0, @_);
394 }
395
396 #
397 # lock_retrieve
398 #
399 # Same as retrieve, but with advisory locking.
400 #
401 sub lock_retrieve {
402     _retrieve(shift, 1, @_);
403 }
404
405 # Internal retrieve routine
406 sub _retrieve {
407     my ($file, $use_locking, $flags) = @_;
408     $flags = $Storable::flags unless defined $flags;
409     my $FILE;
410     open($FILE, "<", $file) || logcroak "can't open $file: $!";
411     binmode $FILE;                      # Archaic systems...
412     my $self;
413     my $da = $@;                        # Could be from exception handler
414     if ($use_locking) {
415         unless (&CAN_FLOCK) {
416             logcarp
417               "Storable::lock_store: fcntl/flock emulation broken on $^O";
418             return undef;
419         }
420         flock($FILE, LOCK_SH) || logcroak "can't get shared lock on $file: $!";
421         # Unlocking will happen when FILE is closed
422     }
423     eval { $self = pretrieve($FILE, $flags) };          # Call C routine
424     close($FILE);
425     if ($@) {
426         $@ =~ s/\.?\n$/,/ unless ref $@;
427         logcroak $@;
428     }
429     $@ = $da;
430     return $self;
431 }
432
433 #
434 # fd_retrieve
435 #
436 # Same as retrieve, but perform from an already opened file descriptor instead.
437 #
438 sub fd_retrieve {
439     my ($file, $flags) = @_;
440     $flags = $Storable::flags unless defined $flags;
441     my $fd = fileno($file);
442     logcroak "not a valid file descriptor" unless defined $fd;
443     my $self;
444     my $da = $@;                                # Could be from exception handler
445     eval { $self = pretrieve($file, $flags) };  # Call C routine
446     if ($@) {
447         $@ =~ s/\.?\n$/,/ unless ref $@;
448         logcroak $@;
449     }
450     $@ = $da;
451     return $self;
452 }
453
454 sub retrieve_fd { &fd_retrieve }                # Backward compatibility
455
456 #
457 # thaw
458 #
459 # Recreate objects in memory from an existing frozen image created
460 # by freeze.  If the frozen image passed is undef, return undef.
461 #
462 # thaw(frozen_obj, flags)
463 # flags include by default BLESS_OK=2 | TIE_OK=4
464 # with flags=0 or the global $Storable::flags set to 0, no resulting object
465 # will be blessed nor tied.
466 #
467 sub thaw {
468     my ($frozen, $flags) = @_;
469     $flags = $Storable::flags unless defined $flags;
470     return undef unless defined $frozen;
471     my $self;
472     my $da = $@;                                # Could be from exception handler
473     eval { $self = mretrieve($frozen, $flags) };# Call C routine
474     if ($@) {
475         $@ =~ s/\.?\n$/,/ unless ref $@;
476         logcroak $@;
477     }
478     $@ = $da;
479     return $self;
480 }
481
482 #
483 # _make_re($re, $flags)
484 #
485 # Internal function used to thaw a regular expression.
486 #
487
488 my $re_flags;
489 BEGIN {
490     if ($] < 5.010) {
491         $re_flags = qr/\A[imsx]*\z/;
492     }
493     elsif ($] < 5.014) {
494         $re_flags = qr/\A[msixp]*\z/;
495     }
496     elsif ($] < 5.022) {
497         $re_flags = qr/\A[msixpdual]*\z/;
498     }
499     else {
500         $re_flags = qr/\A[msixpdualn]*\z/;
501     }
502 }
503
504 sub _make_re {
505     my ($re, $flags) = @_;
506
507     $flags =~ $re_flags
508         or die "regexp flags invalid";
509
510     my $qr = eval "qr/\$re/$flags";
511     die $@ if $@;
512
513     $qr;
514 }
515
516 if ($] < 5.012) {
517     eval <<'EOS'
518 sub _regexp_pattern {
519     my $re = "" . shift;
520     $re =~ /\A\(\?([xism]*)(?:-[xism]*)?:(.*)\)\z/s
521         or die "Cannot parse regexp /$re/";
522     return ($2, $1);
523 }
524 1
525 EOS
526       or die "Cannot define _regexp_pattern: $@";
527 }
528
529 1;
530 __END__
531
532 =head1 NAME
533
534 Storable - persistence for Perl data structures
535
536 =head1 SYNOPSIS
537
538  use Storable;
539  store \%table, 'file';
540  $hashref = retrieve('file');
541
542  use Storable qw(nstore store_fd nstore_fd freeze thaw dclone);
543
544  # Network order
545  nstore \%table, 'file';
546  $hashref = retrieve('file');   # There is NO nretrieve()
547
548  # Storing to and retrieving from an already opened file
549  store_fd \@array, \*STDOUT;
550  nstore_fd \%table, \*STDOUT;
551  $aryref = fd_retrieve(\*SOCKET);
552  $hashref = fd_retrieve(\*SOCKET);
553
554  # Serializing to memory
555  $serialized = freeze \%table;
556  %table_clone = %{ thaw($serialized) };
557
558  # Deep (recursive) cloning
559  $cloneref = dclone($ref);
560
561  # Advisory locking
562  use Storable qw(lock_store lock_nstore lock_retrieve)
563  lock_store \%table, 'file';
564  lock_nstore \%table, 'file';
565  $hashref = lock_retrieve('file');
566
567 =head1 DESCRIPTION
568
569 The Storable package brings persistence to your Perl data structures
570 containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be
571 conveniently stored to disk and retrieved at a later time.
572
573 It can be used in the regular procedural way by calling C<store> with
574 a reference to the object to be stored, along with the file name where
575 the image should be written.
576
577 The routine returns C<undef> for I/O problems or other internal error,
578 a true value otherwise. Serious errors are propagated as a C<die> exception.
579
580 To retrieve data stored to disk, use C<retrieve> with a file name.
581 The objects stored into that file are recreated into memory for you,
582 and a I<reference> to the root object is returned. In case an I/O error
583 occurs while reading, C<undef> is returned instead. Other serious
584 errors are propagated via C<die>.
585
586 Since storage is performed recursively, you might want to stuff references
587 to objects that share a lot of common data into a single array or hash
588 table, and then store that object. That way, when you retrieve back the
589 whole thing, the objects will continue to share what they originally shared.
590
591 At the cost of a slight header overhead, you may store to an already
592 opened file descriptor using the C<store_fd> routine, and retrieve
593 from a file via C<fd_retrieve>. Those names aren't imported by default,
594 so you will have to do that explicitly if you need those routines.
595 The file descriptor you supply must be already opened, for read
596 if you're going to retrieve and for write if you wish to store.
597
598         store_fd(\%table, *STDOUT) || die "can't store to stdout\n";
599         $hashref = fd_retrieve(*STDIN);
600
601 You can also store data in network order to allow easy sharing across
602 multiple platforms, or when storing on a socket known to be remotely
603 connected. The routines to call have an initial C<n> prefix for I<network>,
604 as in C<nstore> and C<nstore_fd>. At retrieval time, your data will be
605 correctly restored so you don't have to know whether you're restoring
606 from native or network ordered data.  Double values are stored stringified
607 to ensure portability as well, at the slight risk of loosing some precision
608 in the last decimals.
609
610 When using C<fd_retrieve>, objects are retrieved in sequence, one
611 object (i.e. one recursive tree) per associated C<store_fd>.
612
613 If you're more from the object-oriented camp, you can inherit from
614 Storable and directly store your objects by invoking C<store> as
615 a method. The fact that the root of the to-be-stored tree is a
616 blessed reference (i.e. an object) is special-cased so that the
617 retrieve does not provide a reference to that object but rather the
618 blessed object reference itself. (Otherwise, you'd get a reference
619 to that blessed object).
620
621 =head1 MEMORY STORE
622
623 The Storable engine can also store data into a Perl scalar instead, to
624 later retrieve them. This is mainly used to freeze a complex structure in
625 some safe compact memory place (where it can possibly be sent to another
626 process via some IPC, since freezing the structure also serializes it in
627 effect). Later on, and maybe somewhere else, you can thaw the Perl scalar
628 out and recreate the original complex structure in memory.
629
630 Surprisingly, the routines to be called are named C<freeze> and C<thaw>.
631 If you wish to send out the frozen scalar to another machine, use
632 C<nfreeze> instead to get a portable image.
633
634 Note that freezing an object structure and immediately thawing it
635 actually achieves a deep cloning of that structure:
636
637     dclone(.) = thaw(freeze(.))
638
639 Storable provides you with a C<dclone> interface which does not create
640 that intermediary scalar but instead freezes the structure in some
641 internal memory space and then immediately thaws it out.
642
643 =head1 ADVISORY LOCKING
644
645 The C<lock_store> and C<lock_nstore> routine are equivalent to
646 C<store> and C<nstore>, except that they get an exclusive lock on
647 the file before writing.  Likewise, C<lock_retrieve> does the same
648 as C<retrieve>, but also gets a shared lock on the file before reading.
649
650 As with any advisory locking scheme, the protection only works if you
651 systematically use C<lock_store> and C<lock_retrieve>.  If one side of
652 your application uses C<store> whilst the other uses C<lock_retrieve>,
653 you will get no protection at all.
654
655 The internal advisory locking is implemented using Perl's flock()
656 routine.  If your system does not support any form of flock(), or if
657 you share your files across NFS, you might wish to use other forms
658 of locking by using modules such as LockFile::Simple which lock a
659 file using a filesystem entry, instead of locking the file descriptor.
660
661 =head1 SPEED
662
663 The heart of Storable is written in C for decent speed. Extra low-level
664 optimizations have been made when manipulating perl internals, to
665 sacrifice encapsulation for the benefit of greater speed.
666
667 =head1 CANONICAL REPRESENTATION
668
669 Normally, Storable stores elements of hashes in the order they are
670 stored internally by Perl, i.e. pseudo-randomly.  If you set
671 C<$Storable::canonical> to some C<TRUE> value, Storable will store
672 hashes with the elements sorted by their key.  This allows you to
673 compare data structures by comparing their frozen representations (or
674 even the compressed frozen representations), which can be useful for
675 creating lookup tables for complicated queries.
676
677 Canonical order does not imply network order; those are two orthogonal
678 settings.
679
680 =head1 CODE REFERENCES
681
682 Since Storable version 2.05, CODE references may be serialized with
683 the help of L<B::Deparse>. To enable this feature, set
684 C<$Storable::Deparse> to a true value. To enable deserialization,
685 C<$Storable::Eval> should be set to a true value. Be aware that
686 deserialization is done through C<eval>, which is dangerous if the
687 Storable file contains malicious data. You can set C<$Storable::Eval>
688 to a subroutine reference which would be used instead of C<eval>. See
689 below for an example using a L<Safe> compartment for deserialization
690 of CODE references.
691
692 If C<$Storable::Deparse> and/or C<$Storable::Eval> are set to false
693 values, then the value of C<$Storable::forgive_me> (see below) is
694 respected while serializing and deserializing.
695
696 =head1 FORWARD COMPATIBILITY
697
698 This release of Storable can be used on a newer version of Perl to
699 serialize data which is not supported by earlier Perls.  By default,
700 Storable will attempt to do the right thing, by C<croak()>ing if it
701 encounters data that it cannot deserialize.  However, the defaults
702 can be changed as follows:
703
704 =over 4
705
706 =item utf8 data
707
708 Perl 5.6 added support for Unicode characters with code points > 255,
709 and Perl 5.8 has full support for Unicode characters in hash keys.
710 Perl internally encodes strings with these characters using utf8, and
711 Storable serializes them as utf8.  By default, if an older version of
712 Perl encounters a utf8 value it cannot represent, it will C<croak()>.
713 To change this behaviour so that Storable deserializes utf8 encoded
714 values as the string of bytes (effectively dropping the I<is_utf8> flag)
715 set C<$Storable::drop_utf8> to some C<TRUE> value.  This is a form of
716 data loss, because with C<$drop_utf8> true, it becomes impossible to tell
717 whether the original data was the Unicode string, or a series of bytes
718 that happen to be valid utf8.
719
720 =item restricted hashes
721
722 Perl 5.8 adds support for restricted hashes, which have keys
723 restricted to a given set, and can have values locked to be read only.
724 By default, when Storable encounters a restricted hash on a perl
725 that doesn't support them, it will deserialize it as a normal hash,
726 silently discarding any placeholder keys and leaving the keys and
727 all values unlocked.  To make Storable C<croak()> instead, set
728 C<$Storable::downgrade_restricted> to a C<FALSE> value.  To restore
729 the default set it back to some C<TRUE> value.
730
731 The cperl PERL_PERTURB_KEYS_TOP hash strategy has a known problem with
732 restricted hashes.
733
734 =item huge objects
735
736 On 64bit systems some data structures may exceed the 2G (i.e. I32_MAX)
737 limit. On 32bit systems also strings between I32 and U32 (2G-4G).
738 Since Storable 3.00 (not in perl5 core) we are able to store and
739 retrieve these objects, even if perl5 itself is not able to handle
740 them.  These are strings longer then 4G, arrays with more then 2G
741 elements and hashes with more then 2G elements. cperl forbids hashes
742 with more than 2G elements, but this fail in cperl then. perl5 itself
743 at least until 5.26 allows it, but cannot iterate over them.
744 Note that creating those objects might cause out of memory
745 exceptions by the operating system before perl has a chance to abort.
746
747 =item files from future versions of Storable
748
749 Earlier versions of Storable would immediately croak if they encountered
750 a file with a higher internal version number than the reading Storable
751 knew about.  Internal version numbers are increased each time new data
752 types (such as restricted hashes) are added to the vocabulary of the file
753 format.  This meant that a newer Storable module had no way of writing a
754 file readable by an older Storable, even if the writer didn't store newer
755 data types.
756
757 This version of Storable will defer croaking until it encounters a data
758 type in the file that it does not recognize.  This means that it will
759 continue to read files generated by newer Storable modules which are careful
760 in what they write out, making it easier to upgrade Storable modules in a
761 mixed environment.
762
763 The old behaviour of immediate croaking can be re-instated by setting
764 C<$Storable::accept_future_minor> to some C<FALSE> value.
765
766 =back
767
768 All these variables have no effect on a newer Perl which supports the
769 relevant feature.
770
771 =head1 ERROR REPORTING
772
773 Storable uses the "exception" paradigm, in that it does not try to
774 workaround failures: if something bad happens, an exception is
775 generated from the caller's perspective (see L<Carp> and C<croak()>).
776 Use eval {} to trap those exceptions.
777
778 When Storable croaks, it tries to report the error via the C<logcroak()>
779 routine from the C<Log::Agent> package, if it is available.
780
781 Normal errors are reported by having store() or retrieve() return C<undef>.
782 Such errors are usually I/O errors (or truncated stream errors at retrieval).
783
784 When Storable throws the "Max. recursion depth with nested structures
785 exceeded" error we are already out of stack space. Unfortunately on
786 some earlier perl versions cleaning up a recursive data structure
787 recurses into the free calls, which will lead to stack overflows in
788 the cleanup. This data structure is not properly cleaned up then, it
789 will only be destroyed during global destruction.
790
791 =head1 WIZARDS ONLY
792
793 =head2 Hooks
794
795 Any class may define hooks that will be called during the serialization
796 and deserialization process on objects that are instances of that class.
797 Those hooks can redefine the way serialization is performed (and therefore,
798 how the symmetrical deserialization should be conducted).
799
800 Since we said earlier:
801
802     dclone(.) = thaw(freeze(.))
803
804 everything we say about hooks should also hold for deep cloning. However,
805 hooks get to know whether the operation is a mere serialization, or a cloning.
806
807 Therefore, when serializing hooks are involved,
808
809     dclone(.) <> thaw(freeze(.))
810
811 Well, you could keep them in sync, but there's no guarantee it will always
812 hold on classes somebody else wrote.  Besides, there is little to gain in
813 doing so: a serializing hook could keep only one attribute of an object,
814 which is probably not what should happen during a deep cloning of that
815 same object.
816
817 Here is the hooking interface:
818
819 =over 4
820
821 =item C<STORABLE_freeze> I<obj>, I<cloning>
822
823 The serializing hook, called on the object during serialization.  It can be
824 inherited, or defined in the class itself, like any other method.
825
826 Arguments: I<obj> is the object to serialize, I<cloning> is a flag indicating
827 whether we're in a dclone() or a regular serialization via store() or freeze().
828
829 Returned value: A LIST C<($serialized, $ref1, $ref2, ...)> where $serialized
830 is the serialized form to be used, and the optional $ref1, $ref2, etc... are
831 extra references that you wish to let the Storable engine serialize.
832
833 At deserialization time, you will be given back the same LIST, but all the
834 extra references will be pointing into the deserialized structure.
835
836 The B<first time> the hook is hit in a serialization flow, you may have it
837 return an empty list.  That will signal the Storable engine to further
838 discard that hook for this class and to therefore revert to the default
839 serialization of the underlying Perl data.  The hook will again be normally
840 processed in the next serialization.
841
842 Unless you know better, serializing hook should always say:
843
844     sub STORABLE_freeze {
845         my ($self, $cloning) = @_;
846         return if $cloning;         # Regular default serialization
847         ....
848     }
849
850 in order to keep reasonable dclone() semantics.
851
852 =item C<STORABLE_thaw> I<obj>, I<cloning>, I<serialized>, ...
853
854 The deserializing hook called on the object during deserialization.
855 But wait: if we're deserializing, there's no object yet... right?
856
857 Wrong: the Storable engine creates an empty one for you.  If you know Eiffel,
858 you can view C<STORABLE_thaw> as an alternate creation routine.
859
860 This means the hook can be inherited like any other method, and that
861 I<obj> is your blessed reference for this particular instance.
862
863 The other arguments should look familiar if you know C<STORABLE_freeze>:
864 I<cloning> is true when we're part of a deep clone operation, I<serialized>
865 is the serialized string you returned to the engine in C<STORABLE_freeze>,
866 and there may be an optional list of references, in the same order you gave
867 them at serialization time, pointing to the deserialized objects (which
868 have been processed courtesy of the Storable engine).
869
870 When the Storable engine does not find any C<STORABLE_thaw> hook routine,
871 it tries to load the class by requiring the package dynamically (using
872 the blessed package name), and then re-attempts the lookup.  If at that
873 time the hook cannot be located, the engine croaks.  Note that this mechanism
874 will fail if you define several classes in the same file, but L<perlmod>
875 warned you.
876
877 It is up to you to use this information to populate I<obj> the way you want.
878
879 Returned value: none.
880
881 =item C<STORABLE_attach> I<class>, I<cloning>, I<serialized>
882
883 While C<STORABLE_freeze> and C<STORABLE_thaw> are useful for classes where
884 each instance is independent, this mechanism has difficulty (or is
885 incompatible) with objects that exist as common process-level or
886 system-level resources, such as singleton objects, database pools, caches
887 or memoized objects.
888
889 The alternative C<STORABLE_attach> method provides a solution for these
890 shared objects. Instead of C<STORABLE_freeze> --E<gt> C<STORABLE_thaw>,
891 you implement C<STORABLE_freeze> --E<gt> C<STORABLE_attach> instead.
892
893 Arguments: I<class> is the class we are attaching to, I<cloning> is a flag
894 indicating whether we're in a dclone() or a regular de-serialization via
895 thaw(), and I<serialized> is the stored string for the resource object.
896
897 Because these resource objects are considered to be owned by the entire
898 process/system, and not the "property" of whatever is being serialized,
899 no references underneath the object should be included in the serialized
900 string. Thus, in any class that implements C<STORABLE_attach>, the
901 C<STORABLE_freeze> method cannot return any references, and C<Storable>
902 will throw an error if C<STORABLE_freeze> tries to return references.
903
904 All information required to "attach" back to the shared resource object
905 B<must> be contained B<only> in the C<STORABLE_freeze> return string.
906 Otherwise, C<STORABLE_freeze> behaves as normal for C<STORABLE_attach>
907 classes.
908
909 Because C<STORABLE_attach> is passed the class (rather than an object),
910 it also returns the object directly, rather than modifying the passed
911 object.
912
913 Returned value: object of type C<class>
914
915 =back
916
917 =head2 Predicates
918
919 Predicates are not exportable.  They must be called by explicitly prefixing
920 them with the Storable package name.
921
922 =over 4
923
924 =item C<Storable::last_op_in_netorder>
925
926 The C<Storable::last_op_in_netorder()> predicate will tell you whether
927 network order was used in the last store or retrieve operation.  If you
928 don't know how to use this, just forget about it.
929
930 =item C<Storable::is_storing>
931
932 Returns true if within a store operation (via STORABLE_freeze hook).
933
934 =item C<Storable::is_retrieving>
935
936 Returns true if within a retrieve operation (via STORABLE_thaw hook).
937
938 =back
939
940 =head2 Recursion
941
942 With hooks comes the ability to recurse back to the Storable engine.
943 Indeed, hooks are regular Perl code, and Storable is convenient when
944 it comes to serializing and deserializing things, so why not use it
945 to handle the serialization string?
946
947 There are a few things you need to know, however:
948
949 =over 4
950
951 =item *
952
953 Since Storable 3.05 we probe for the stack recursion limit for references,
954 arrays and hashes to a maximal depth of ~1200-35000, otherwise we might
955 fall into a stack-overflow.  On JSON::XS this limit is 512 btw.  With
956 references not immediately referencing each other there's no such
957 limit yet, so you might fall into such a stack-overflow segfault.
958
959 This probing and the checks performed have some limitations:
960
961 =over
962
963 =item *
964
965 the stack size at build time might be different at run time, eg. the
966 stack size may have been modified with ulimit(1).  If it's larger at
967 run time Storable may fail the freeze() or thaw() unnecessarily.
968
969 =item *
970
971 the stack size might be different in a thread.
972
973 =item *
974
975 array and hash recursion limits are checked separately against the
976 same recursion depth, a frozen structure with a large sequence of
977 nested arrays within many nested hashes may exhaust the processor
978 stack without triggering Storable's recursion protection.
979
980 =back
981
982 You can control the maximum array and hash recursion depths by
983 modifying C<$Storable::recursion_limit> and
984 C<$Storable::recursion_limit_hash> respectively.  Either can be set to
985 C<-1> to prevent any depth checks, though this isn't recommended.
986
987 =item *
988
989 You can create endless loops if the things you serialize via freeze()
990 (for instance) point back to the object we're trying to serialize in
991 the hook.
992
993 =item *
994
995 Shared references among objects will not stay shared: if we're serializing
996 the list of object [A, C] where both object A and C refer to the SAME object
997 B, and if there is a serializing hook in A that says freeze(B), then when
998 deserializing, we'll get [A', C'] where A' refers to B', but C' refers to D,
999 a deep clone of B'.  The topology was not preserved.
1000
1001 =item *
1002
1003 The maximal stack recursion limit for your system is returned by
1004 C<stack_depth()> and C<stack_depth_hash()>. The hash limit is usually
1005 half the size of the array and ref limit, as the Perl hash API is not optimal.
1006
1007 =back
1008
1009 That's why C<STORABLE_freeze> lets you provide a list of references
1010 to serialize.  The engine guarantees that those will be serialized in the
1011 same context as the other objects, and therefore that shared objects will
1012 stay shared.
1013
1014 In the above [A, C] example, the C<STORABLE_freeze> hook could return:
1015
1016         ("something", $self->{B})
1017
1018 and the B part would be serialized by the engine.  In C<STORABLE_thaw>, you
1019 would get back the reference to the B' object, deserialized for you.
1020
1021 Therefore, recursion should normally be avoided, but is nonetheless supported.
1022
1023 =head2 Deep Cloning
1024
1025 There is a Clone module available on CPAN which implements deep cloning
1026 natively, i.e. without freezing to memory and thawing the result.  It is
1027 aimed to replace Storable's dclone() some day.  However, it does not currently
1028 support Storable hooks to redefine the way deep cloning is performed.
1029
1030 =head1 Storable magic
1031
1032 Yes, there's a lot of that :-) But more precisely, in UNIX systems
1033 there's a utility called C<file>, which recognizes data files based on
1034 their contents (usually their first few bytes).  For this to work,
1035 a certain file called F<magic> needs to taught about the I<signature>
1036 of the data.  Where that configuration file lives depends on the UNIX
1037 flavour; often it's something like F</usr/share/misc/magic> or
1038 F</etc/magic>.  Your system administrator needs to do the updating of
1039 the F<magic> file.  The necessary signature information is output to
1040 STDOUT by invoking Storable::show_file_magic().  Note that the GNU
1041 implementation of the C<file> utility, version 3.38 or later,
1042 is expected to contain support for recognising Storable files
1043 out-of-the-box, in addition to other kinds of Perl files.
1044
1045 You can also use the following functions to extract the file header
1046 information from Storable images:
1047
1048 =over
1049
1050 =item $info = Storable::file_magic( $filename )
1051
1052 If the given file is a Storable image return a hash describing it.  If
1053 the file is readable, but not a Storable image return C<undef>.  If
1054 the file does not exist or is unreadable then croak.
1055
1056 The hash returned has the following elements:
1057
1058 =over
1059
1060 =item C<version>
1061
1062 This returns the file format version.  It is a string like "2.7".
1063
1064 Note that this version number is not the same as the version number of
1065 the Storable module itself.  For instance Storable v0.7 create files
1066 in format v2.0 and Storable v2.15 create files in format v2.7.  The
1067 file format version number only increment when additional features
1068 that would confuse older versions of the module are added.
1069
1070 Files older than v2.0 will have the one of the version numbers "-1",
1071 "0" or "1".  No minor number was used at that time.
1072
1073 =item C<version_nv>
1074
1075 This returns the file format version as number.  It is a string like
1076 "2.007".  This value is suitable for numeric comparisons.
1077
1078 The constant function C<Storable::BIN_VERSION_NV> returns a comparable
1079 number that represents the highest file version number that this
1080 version of Storable fully supports (but see discussion of
1081 C<$Storable::accept_future_minor> above).  The constant
1082 C<Storable::BIN_WRITE_VERSION_NV> function returns what file version
1083 is written and might be less than C<Storable::BIN_VERSION_NV> in some
1084 configurations.
1085
1086 =item C<major>, C<minor>
1087
1088 This also returns the file format version.  If the version is "2.7"
1089 then major would be 2 and minor would be 7.  The minor element is
1090 missing for when major is less than 2.
1091
1092 =item C<hdrsize>
1093
1094 The is the number of bytes that the Storable header occupies.
1095
1096 =item C<netorder>
1097
1098 This is TRUE if the image store data in network order.  This means
1099 that it was created with nstore() or similar.
1100
1101 =item C<byteorder>
1102
1103 This is only present when C<netorder> is FALSE.  It is the
1104 $Config{byteorder} string of the perl that created this image.  It is
1105 a string like "1234" (32 bit little endian) or "87654321" (64 bit big
1106 endian).  This must match the current perl for the image to be
1107 readable by Storable.
1108
1109 =item C<intsize>, C<longsize>, C<ptrsize>, C<nvsize>
1110
1111 These are only present when C<netorder> is FALSE. These are the sizes of
1112 various C datatypes of the perl that created this image.  These must
1113 match the current perl for the image to be readable by Storable.
1114
1115 The C<nvsize> element is only present for file format v2.2 and
1116 higher.
1117
1118 =item C<file>
1119
1120 The name of the file.
1121
1122 =back
1123
1124 =item $info = Storable::read_magic( $buffer )
1125
1126 =item $info = Storable::read_magic( $buffer, $must_be_file )
1127
1128 The $buffer should be a Storable image or the first few bytes of it.
1129 If $buffer starts with a Storable header, then a hash describing the
1130 image is returned, otherwise C<undef> is returned.
1131
1132 The hash has the same structure as the one returned by
1133 Storable::file_magic().  The C<file> element is true if the image is a
1134 file image.
1135
1136 If the $must_be_file argument is provided and is TRUE, then return
1137 C<undef> unless the image looks like it belongs to a file dump.
1138
1139 The maximum size of a Storable header is currently 21 bytes.  If the
1140 provided $buffer is only the first part of a Storable image it should
1141 at least be this long to ensure that read_magic() will recognize it as
1142 such.
1143
1144 =back
1145
1146 =head1 EXAMPLES
1147
1148 Here are some code samples showing a possible usage of Storable:
1149
1150  use Storable qw(store retrieve freeze thaw dclone);
1151
1152  %color = ('Blue' => 0.1, 'Red' => 0.8, 'Black' => 0, 'White' => 1);
1153
1154  store(\%color, 'mycolors') or die "Can't store %a in mycolors!\n";
1155
1156  $colref = retrieve('mycolors');
1157  die "Unable to retrieve from mycolors!\n" unless defined $colref;
1158  printf "Blue is still %lf\n", $colref->{'Blue'};
1159
1160  $colref2 = dclone(\%color);
1161
1162  $str = freeze(\%color);
1163  printf "Serialization of %%color is %d bytes long.\n", length($str);
1164  $colref3 = thaw($str);
1165
1166 which prints (on my machine):
1167
1168  Blue is still 0.100000
1169  Serialization of %color is 102 bytes long.
1170
1171 Serialization of CODE references and deserialization in a safe
1172 compartment:
1173
1174 =for example begin
1175
1176  use Storable qw(freeze thaw);
1177  use Safe;
1178  use strict;
1179  my $safe = new Safe;
1180         # because of opcodes used in "use strict":
1181  $safe->permit(qw(:default require));
1182  local $Storable::Deparse = 1;
1183  local $Storable::Eval = sub { $safe->reval($_[0]) };
1184  my $serialized = freeze(sub { 42 });
1185  my $code = thaw($serialized);
1186  $code->() == 42;
1187
1188 =for example end
1189
1190 =for example_testing
1191         is( $code->(), 42 );
1192
1193 =head1 SECURITY WARNING
1194
1195 B<Do not accept Storable documents from untrusted sources!>
1196
1197 Some features of Storable can lead to security vulnerabilities if you
1198 accept Storable documents from untrusted sources with the default
1199 flags. Most obviously, the optional (off by default) CODE reference
1200 serialization feature allows transfer of code to the deserializing
1201 process. Furthermore, any serialized object will cause Storable to
1202 helpfully load the module corresponding to the class of the object in
1203 the deserializing module.  For manipulated module names, this can load
1204 almost arbitrary code.  Finally, the deserialized object's destructors
1205 will be invoked when the objects get destroyed in the deserializing
1206 process. Maliciously crafted Storable documents may put such objects
1207 in the value of a hash key that is overridden by another key/value
1208 pair in the same hash, thus causing immediate destructor execution.
1209
1210 To disable blessing objects while thawing/retrieving remove the flag
1211 C<BLESS_OK> = 2 from C<$Storable::flags> or set the 2nd argument for
1212 thaw/retrieve to 0.
1213
1214 To disable tieing data while thawing/retrieving remove the flag C<TIE_OK>
1215 = 4 from C<$Storable::flags> or set the 2nd argument for thaw/retrieve
1216 to 0.
1217
1218 With the default setting of C<$Storable::flags> = 6, creating or destroying
1219 random objects, even renamed objects can be controlled by an attacker.
1220 See CVE-2015-1592 and its metasploit module.
1221
1222 If your application requires accepting data from untrusted sources,
1223 you are best off with a less powerful and more-likely safe
1224 serialization format and implementation. If your data is sufficiently
1225 simple, Cpanel::JSON::XS, Data::MessagePack or Serial are the best
1226 choices and offers maximum interoperability, but note that Serial is
1227 unsafe by default.
1228
1229 =head1 WARNING
1230
1231 If you're using references as keys within your hash tables, you're bound
1232 to be disappointed when retrieving your data. Indeed, Perl stringifies
1233 references used as hash table keys. If you later wish to access the
1234 items via another reference stringification (i.e. using the same
1235 reference that was used for the key originally to record the value into
1236 the hash table), it will work because both references stringify to the
1237 same string.
1238
1239 It won't work across a sequence of C<store> and C<retrieve> operations,
1240 however, because the addresses in the retrieved objects, which are
1241 part of the stringified references, will probably differ from the
1242 original addresses. The topology of your structure is preserved,
1243 but not hidden semantics like those.
1244
1245 On platforms where it matters, be sure to call C<binmode()> on the
1246 descriptors that you pass to Storable functions.
1247
1248 Storing data canonically that contains large hashes can be
1249 significantly slower than storing the same data normally, as
1250 temporary arrays to hold the keys for each hash have to be allocated,
1251 populated, sorted and freed.  Some tests have shown a halving of the
1252 speed of storing -- the exact penalty will depend on the complexity of
1253 your data.  There is no slowdown on retrieval.
1254
1255 =head1 REGULAR EXPRESSIONS
1256
1257 Storable now has experimental support for storing regular expressions,
1258 but there are significant limitations:
1259
1260 =over
1261
1262 =item *
1263
1264 perl 5.8 or later is required.
1265
1266 =item *
1267
1268 regular expressions with code blocks, ie C</(?{ ... })/> or C</(??{
1269 ... })/> will throw an exception when thawed.
1270
1271 =item *
1272
1273 regular expression syntax and flags have changed over the history of
1274 perl, so a regular expression that you freeze in one version of perl
1275 may fail to thaw or behave differently in another version of perl.
1276
1277 =item *
1278
1279 depending on the version of perl, regular expressions can change in
1280 behaviour depending on the context, but later perls will bake that
1281 behaviour into the regexp.
1282
1283 =back
1284
1285 Storable will throw an exception if a frozen regular expression cannot
1286 be thawed.
1287
1288 =head1 BUGS
1289
1290 You can't store GLOB, FORMLINE, etc.... If you can define semantics
1291 for those operations, feel free to enhance Storable so that it can
1292 deal with them.
1293
1294 The store functions will C<croak> if they run into such references
1295 unless you set C<$Storable::forgive_me> to some C<TRUE> value. In that
1296 case, the fatal message is converted to a warning and some meaningless
1297 string is stored instead.
1298
1299 Setting C<$Storable::canonical> may not yield frozen strings that
1300 compare equal due to possible stringification of numbers. When the
1301 string version of a scalar exists, it is the form stored; therefore,
1302 if you happen to use your numbers as strings between two freezing
1303 operations on the same data structures, you will get different
1304 results.
1305
1306 When storing doubles in network order, their value is stored as text.
1307 However, you should also not expect non-numeric floating-point values
1308 such as infinity and "not a number" to pass successfully through a
1309 nstore()/retrieve() pair.
1310
1311 As Storable neither knows nor cares about character sets (although it
1312 does know that characters may be more than eight bits wide), any difference
1313 in the interpretation of character codes between a host and a target
1314 system is your problem.  In particular, if host and target use different
1315 code points to represent the characters used in the text representation
1316 of floating-point numbers, you will not be able be able to exchange
1317 floating-point data, even with nstore().
1318
1319 C<Storable::drop_utf8> is a blunt tool.  There is no facility either to
1320 return B<all> strings as utf8 sequences, or to attempt to convert utf8
1321 data back to 8 bit and C<croak()> if the conversion fails.
1322
1323 Prior to Storable 2.01, no distinction was made between signed and
1324 unsigned integers on storing.  By default Storable prefers to store a
1325 scalars string representation (if it has one) so this would only cause
1326 problems when storing large unsigned integers that had never been converted
1327 to string or floating point.  In other words values that had been generated
1328 by integer operations such as logic ops and then not used in any string or
1329 arithmetic context before storing.
1330
1331 =head2 64 bit data in perl 5.6.0 and 5.6.1
1332
1333 This section only applies to you if you have existing data written out
1334 by Storable 2.02 or earlier on perl 5.6.0 or 5.6.1 on Unix or Linux which
1335 has been configured with 64 bit integer support (not the default)
1336 If you got a precompiled perl, rather than running Configure to build
1337 your own perl from source, then it almost certainly does not affect you,
1338 and you can stop reading now (unless you're curious). If you're using perl
1339 on Windows it does not affect you.
1340
1341 Storable writes a file header which contains the sizes of various C
1342 language types for the C compiler that built Storable (when not writing in
1343 network order), and will refuse to load files written by a Storable not
1344 on the same (or compatible) architecture.  This check and a check on
1345 machine byteorder is needed because the size of various fields in the file
1346 are given by the sizes of the C language types, and so files written on
1347 different architectures are incompatible.  This is done for increased speed.
1348 (When writing in network order, all fields are written out as standard
1349 lengths, which allows full interworking, but takes longer to read and write)
1350
1351 Perl 5.6.x introduced the ability to optional configure the perl interpreter
1352 to use C's C<long long> type to allow scalars to store 64 bit integers on 32
1353 bit systems.  However, due to the way the Perl configuration system
1354 generated the C configuration files on non-Windows platforms, and the way
1355 Storable generates its header, nothing in the Storable file header reflected
1356 whether the perl writing was using 32 or 64 bit integers, despite the fact
1357 that Storable was storing some data differently in the file.  Hence Storable
1358 running on perl with 64 bit integers will read the header from a file
1359 written by a 32 bit perl, not realise that the data is actually in a subtly
1360 incompatible format, and then go horribly wrong (possibly crashing) if it
1361 encountered a stored integer.  This is a design failure.
1362
1363 Storable has now been changed to write out and read in a file header with
1364 information about the size of integers.  It's impossible to detect whether
1365 an old file being read in was written with 32 or 64 bit integers (they have
1366 the same header) so it's impossible to automatically switch to a correct
1367 backwards compatibility mode.  Hence this Storable defaults to the new,
1368 correct behaviour.
1369
1370 What this means is that if you have data written by Storable 1.x running
1371 on perl 5.6.0 or 5.6.1 configured with 64 bit integers on Unix or Linux
1372 then by default this Storable will refuse to read it, giving the error
1373 I<Byte order is not compatible>.  If you have such data then you
1374 should set C<$Storable::interwork_56_64bit> to a true value to make this
1375 Storable read and write files with the old header.  You should also
1376 migrate your data, or any older perl you are communicating with, to this
1377 current version of Storable.
1378
1379 If you don't have data written with specific configuration of perl described
1380 above, then you do not and should not do anything.  Don't set the flag -
1381 not only will Storable on an identically configured perl refuse to load them,
1382 but Storable a differently configured perl will load them believing them
1383 to be correct for it, and then may well fail or crash part way through
1384 reading them.
1385
1386 =head1 CREDITS
1387
1388 Thank you to (in chronological order):
1389
1390         Jarkko Hietaniemi <jhi@iki.fi>
1391         Ulrich Pfeifer <pfeifer@charly.informatik.uni-dortmund.de>
1392         Benjamin A. Holzman <bholzman@earthlink.net>
1393         Andrew Ford <A.Ford@ford-mason.co.uk>
1394         Gisle Aas <gisle@aas.no>
1395         Jeff Gresham <gresham_jeffrey@jpmorgan.com>
1396         Murray Nesbitt <murray@activestate.com>
1397         Marc Lehmann <pcg@opengroup.org>
1398         Justin Banks <justinb@wamnet.com>
1399         Jarkko Hietaniemi <jhi@iki.fi> (AGAIN, as perl 5.7.0 Pumpkin!)
1400         Salvador Ortiz Garcia <sog@msg.com.mx>
1401         Dominic Dunlop <domo@computer.org>
1402         Erik Haugan <erik@solbors.no>
1403         Benjamin A. Holzman <ben.holzman@grantstreet.com>
1404         Reini Urban <rurban@cpan.org>
1405         Todd Rinaldo <toddr@cpanel.net>
1406         Aaron Crane <arc@cpan.org>
1407
1408 for their bug reports, suggestions and contributions.
1409
1410 Benjamin Holzman contributed the tied variable support, Andrew Ford
1411 contributed the canonical order for hashes, and Gisle Aas fixed
1412 a few misunderstandings of mine regarding the perl internals,
1413 and optimized the emission of "tags" in the output streams by
1414 simply counting the objects instead of tagging them (leading to
1415 a binary incompatibility for the Storable image starting at version
1416 0.6--older images are, of course, still properly understood).
1417 Murray Nesbitt made Storable thread-safe.  Marc Lehmann added overloading
1418 and references to tied items support.  Benjamin Holzman added a performance
1419 improvement for overloaded classes; thanks to Grant Street Group for footing
1420 the bill.
1421 Reini Urban took over maintainance from p5p, and added security fixes
1422 and huge object support.
1423
1424 =head1 AUTHOR
1425
1426 Storable was written by Raphael Manfredi
1427 F<E<lt>Raphael_Manfredi@pobox.comE<gt>>
1428 Maintenance is now done by cperl L<http://perl11.org/cperl>
1429
1430 Please e-mail us with problems, bug fixes, comments and complaints,
1431 although if you have compliments you should send them to Raphael.
1432 Please don't e-mail Raphael with problems, as he no longer works on
1433 Storable, and your message will be delayed while he forwards it to us.
1434
1435 =head1 SEE ALSO
1436
1437 L<Clone>.
1438
1439 =cut