Added Onis::Data::Persistency::Storable.. Not yet tested it, though..
[onis.git] / lib / Onis / Data / Persistent / Storable.pm
1 package Onis::Data::Persistent::Storable;
2
3 use strict;
4 use warnings;
5
6 use Carp (qw(carp confess));
7 use Storable (qw(store retrieve));
8
9 use Onis::Config (qw(get_config));
10 use Onis::Data::Persistent::None (qw($TREE));
11
12 =head1 NAME
13
14 Onis::Data::Persistent::Storable - Storage backend using storable
15
16 =head1 DESCRIPTION
17
18 Simple storage backend that handles data in-memory. At the end of each session
19 the data is read from a storable-dump.
20
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.
24
25 =head1 CONFIGURATION OPTIONS
26
27 =over 4
28
29 =item B<storable_file>: I<E<lt>fileE<gt>>
30
31 Sets the file to use for storable.
32
33 =back
34
35 =cut
36
37 our $StorableFile = get_config ('storable_file') || 'persistency.dat';
38
39 if (-f $StorableFile)
40 {
41         $TREE = retrieve ($StorableFile);
42 }
43
44 if ($::DEBUG & 0x0200)
45 {
46         require Data::Dumper;
47 }
48
49 @Onis::Data::Persistent::Storable::ISA = ('Onis::Data::Persistent::None');
50
51 return (1);
52
53 END
54 {
55         store ($TREE, $StorableFile);
56 }
57
58 =head1 AUTHOR
59
60 Florian octo Forster, E<lt>octo at verplant.orgE<gt>
61
62 =cut