1 2 3 4 5 6 7
use Storable; use Fcntl qw(:DEFAULT :flock); open(DF, "< " . $categoriesFile) or die "can't open " . $categoriesFile . ": $!"; flock(DF, LOCK_SH) or die "can't lock " . $categoriesFile . ": $!"; my @categories = retrieve(*DF); close(DF); return \@categories;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use Path::Tiny qw(path); use Sereal::Encoder qw(encode_sereal SRL_SNAPPY); use Sereal::Decoder qw(decode_sereal); use Test::More; use Test::Deep qw(cmp_deeply); my @categories = 1..100; my $categoriesFile = glob "~/categories.sereal"; { my $path = path($categoriesFile); $path->filehandle({exclusive => 1}, '>'); $path->spew_raw(encode_sereal \@categories, { compress => SRL_SNAPPY, croak_on_bless => 1 }); } { my $path = path($categoriesFile); $path->filehandle({exclusive => 1}, '<'); my @categories2 = decode_sereal($path->slurp_raw, { refuse_objects => 1, validate_utf8 => 1 })->@*; cmp_deeply \@categories, \@categories2; } done_testing;