Commit | Line | Data |
c3c53033 |
1 | #!perl -w |
2 | use strict; |
3 | use vars '$file'; |
4 | |
5 | $file = "storable-testfile.$$"; |
6 | die "Temporary file '$file' already exists" if -e $file; |
7 | |
8 | END { while (-f $file) {unlink $file or die "Can't unlink '$file': $!" }} |
9 | |
10 | use Storable qw (store retrieve freeze thaw nstore nfreeze); |
11 | |
12 | sub slurp { |
13 | my $file = shift; |
14 | local (*FH, $/); |
15 | open FH, "<$file" or die "Can't open '$file': $!"; |
16 | binmode FH; |
17 | my $contents = <FH>; |
18 | die "Can't read $file: $!" unless defined $contents; |
19 | return $contents; |
20 | } |
21 | |
22 | sub store_and_retrieve { |
23 | my $data = shift; |
24 | unlink $file or die "Can't unlink '$file': $!"; |
25 | open FH, ">$file" or die "Can't open '$file': $!"; |
26 | binmode FH; |
27 | print FH $data or die "Can't print to '$file': $!"; |
28 | close FH or die "Can't close '$file': $!"; |
29 | |
30 | return eval {retrieve $file}; |
31 | } |
32 | |
33 | sub freeze_and_thaw { |
34 | my $data = shift; |
35 | return eval {thaw $data}; |
36 | } |
37 | |
38 | $file; |