From: octo Date: Tue, 12 Apr 2005 11:27:26 +0000 (+0000) Subject: Added Onis::Data::Persistency::Storable.. Not yet tested it, though.. X-Git-Tag: Release-0.8.0~20^2~16 X-Git-Url: https://git.octo.it/?p=onis.git;a=commitdiff_plain;h=119c9ff55d96a87f2b0a1cd66460c53c50cb8127;hp=5c1583d69efcd6e65715721bc0013c8afe43b705 Added Onis::Data::Persistency::Storable.. Not yet tested it, though.. --- diff --git a/lib/Onis/Data/Persistent/None.pm b/lib/Onis/Data/Persistent/None.pm index 919fb5a..c8b77fd 100644 --- a/lib/Onis/Data/Persistent/None.pm +++ b/lib/Onis/Data/Persistent/None.pm @@ -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 index 0000000..ae7840a --- /dev/null +++ b/lib/Onis/Data/Persistent/Storable.pm @@ -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 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: IfileE> + +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, Eocto at verplant.orgE + +=cut