Added Onis::Data::Persistency::Storable.. Not yet tested it, though..
authorocto <octo>
Tue, 12 Apr 2005 11:27:26 +0000 (11:27 +0000)
committerocto <octo>
Tue, 12 Apr 2005 11:27:26 +0000 (11:27 +0000)
lib/Onis/Data/Persistent/None.pm
lib/Onis/Data/Persistent/Storable.pm [new file with mode: 0644]

index 919fb5a..c8b77fd 100644 (file)
@@ -2,8 +2,10 @@ package Onis::Data::Persistent::None;
 
 use strict;
 use warnings;
+use vars (qw($TREE));
 
 use Carp qw(carp confess);
+use Exporter;
 
 =head1 NAME
 
@@ -19,7 +21,8 @@ None.
 
 =cut
 
-our $Tree = {};
+@Onis::Data::Persistent::None::EXPORT_OK = (qw($TREE));
+@Onis::Data::Persistent::None::ISA = ('Exporter');
 
 if ($::DEBUG & 0x0200)
 {
@@ -40,14 +43,14 @@ sub new
        
        my $id = $caller . ':' . $name;
        
-       if (exists ($Tree->{$id}))
+       if (exists ($TREE->{$id}))
        {
                print STDERR $/, __FILE__, ": Name $name has been used in context $caller before.";
                return (undef);
        }
 
-       $Tree->{$id} = {};
-       $obj->{'data'} = $Tree->{$id};
+       $TREE->{$id} = {};
+       $obj->{'data'} = $TREE->{$id};
 
        $obj->{'key'} = $key;
        $obj->{'fields'} = [@fields];
diff --git a/lib/Onis/Data/Persistent/Storable.pm b/lib/Onis/Data/Persistent/Storable.pm
new file mode 100644 (file)
index 0000000..ae7840a
--- /dev/null
@@ -0,0 +1,62 @@
+package Onis::Data::Persistent::Storable;
+
+use strict;
+use warnings;
+
+use Carp (qw(carp confess));
+use Storable (qw(store retrieve));
+
+use Onis::Config (qw(get_config));
+use Onis::Data::Persistent::None (qw($TREE));
+
+=head1 NAME
+
+Onis::Data::Persistent::Storable - Storage backend using storable
+
+=head1 DESCRIPTION
+
+Simple storage backend that handles data in-memory. At the end of each session
+the data is read from a storable-dump.
+
+This module is basically a wrapper around L<Onis::Data::Persistent::None> that
+gets the data from a file before and action is taken and writes it back to the
+file after everything has been done.
+
+=head1 CONFIGURATION OPTIONS
+
+=over 4
+
+=item B<storable_file>: I<E<lt>fileE<gt>>
+
+Sets the file to use for storable.
+
+=back
+
+=cut
+
+our $StorableFile = get_config ('storable_file') || 'persistency.dat';
+
+if (-f $StorableFile)
+{
+       $TREE = retrieve ($StorableFile);
+}
+
+if ($::DEBUG & 0x0200)
+{
+       require Data::Dumper;
+}
+
+@Onis::Data::Persistent::Storable::ISA = ('Onis::Data::Persistent::None');
+
+return (1);
+
+END
+{
+       store ($TREE, $StorableFile);
+}
+
+=head1 AUTHOR
+
+Florian octo Forster, E<lt>octo at verplant.orgE<gt>
+
+=cut