thaw#

Reconstruct a Perl structure from a byte string produced by freeze or nfreeze.

Synopsis#

use Storable qw(freeze thaw);
my $data = thaw($bytes);

What you get back#

A reference to the rebuilt structure — the same kind of reference that was passed to freeze or nfreeze. Shared references, circular references, weak references, tied containers, regexps, and blessed objects are all restored. Blessed objects with a STORABLE_thaw hook have the hook run.

thaw auto-detects whether the input came from freeze (native byte order) or nfreeze (network byte order) — the caller does not need to know which producer was used.

Examples#

Basic round trip:

my $bytes = freeze({ n => 1, list => [1, 2, 3] });
my $copy  = thaw($bytes);
print $copy->{list}[2];         # 3

Receive bytes produced on a different machine:

## $buf arrived over the wire from nfreeze on another host

my $msg = thaw($buf);

Edge cases#

  • Empty string or data whose first byte is not a valid tag croaks with a message about corrupt input.

  • If the argument is not a defined string, croaks with argument is not a valid Storable frozen string.

  • Truncation mid-record produces a corrupt-data error, not a partial structure.

Differences from upstream#

  • Only accepts payloads produced by pperl’s freeze / nfreeze. Upstream Storable bytes are rejected as corrupt. Pinned by t/81-xs-native/Storable/010-freeze-thaw.t.

See also#

  • freeze — producer for native-order payloads.

  • nfreeze — producer for portable payloads.

  • retrieve — read a frozen structure back from a file path.

  • fd_retrieve — read from an open file descriptor.