1 package Onis::Data::Persistent::Storable;
6 use Carp (qw(carp confess));
7 use Storable (qw(store retrieve));
9 use Onis::Config (qw(get_config));
10 use Onis::Data::Persistent::None (qw($TREE));
14 Onis::Data::Persistent::Storable - Storage backend using storable
18 Simple storage backend that handles data in-memory. At the end of each session
19 the data is read from a storable-dump.
21 This module is basically a wrapper around L<Onis::Data::Persistent::None> that
22 gets the data from a file before and action is taken and writes it back to the
23 file after everything has been done.
25 =head1 CONFIGURATION OPTIONS
29 =item B<storage_file>: "I<storage.dat>";
31 Sets the file storable will write it's data to.
33 =item B<storage_dir>: "I<var/>";
35 Sets the directory in which B<storage_file> can be found.
41 our $StorageFile = get_config ('storage_file') || 'storage.dat';
42 our $StorageDir = 'var';
43 if (get_config ('storage_dir'))
45 $StorageDir = get_config ('storage_dir');
49 $StorageDir = $ENV{'HOME'} . '/.onis/data';
51 $StorageDir =~ s#/+$##;
55 print STDERR $/, __FILE__, ':', <<ERROR;
57 ``storage_dir'' is set to ``$StorageDir'', but the directory doesn't exist or
58 isn't a directory. Please fix it..
64 if (-f "$StorageDir/$StorageFile")
66 $TREE = retrieve ("$StorageDir/$StorageFile");
69 if ($::DEBUG & 0x0200)
74 @Onis::Data::Persistent::Storable::ISA = ('Onis::Data::Persistent::None');
80 store ($TREE, "$StorageDir/$StorageFile");
85 Florian octo Forster, E<lt>octo at verplant.orgE<gt>