retrieve#

Read a frozen structure from a named file and reconstruct it.

תקציר#

use Storable qw(store retrieve);
my $data = retrieve("cache.bin");

מה מוחזר#

A reference of the same kind that was passed to store or nstore. Byte order is auto-detected, so one retrieve works for files written by either producer.

דוגמאות#

Reload a persisted cache on process start:

my $cache = -e "cache.bin" ? retrieve("cache.bin") : {};

Consume a file produced by nstore on another machine:

my $payload = retrieve("incoming.bin");

מקרי קצה#

  • If the file cannot be opened, croaks with Storable: can't open file for reading.

  • Empty or corrupt files croak with an explicit ”not valid Storable data“ message.

  • A partial read (network interruption, truncated file) is reported as corrupt, never returned as a half-built structure.

הבדלים מן ה-upstream#

  • Only accepts files written by pperl’s store / nstore. Files produced by perl5’s Storable::store are rejected as corrupt. Pinned by t/81-xs-native/Storable/030-store-retrieve.t.

ראו גם#

  • store - matching writer for native-order payloads.

  • nstore - matching writer for portable payloads.

  • fd_retrieve - read from an open filehandle.

  • file_magic - inspect the file’s header without thawing.