1 package Onis::Data::Persistent;
10 Onis::Data::Persistent - Interface for storage backends
14 Abstraction layer for modules that act as a backend and are able to store
15 internal data for longer than one run..
19 use Onis::Config qw#get_config get_checksum#;
21 our $StoreModule = 'None';
23 =head1 CONFIGURATION OPTIONS
25 Since this is a B<interface> the options are very few. One, to be specific. See
26 your favorite backend's documentation on it's options..
30 =item B<storage_module>
32 Selects the storage module to use. Defaults to I<None> which is a dummy module
33 that doesn't do anything with the data.. (Other than storing it internally..)
34 Currently implemented options are:
46 if (get_config ('storage_module'))
48 $StoreModule = ucfirst (lc (get_config ('storage_module')));
52 my $mod_name = "Onis::Data::Persistent::$StoreModule";
54 eval qq(use $mod_name;);
58 print STDERR $/, __FILE__, ": Could not load storage module ``$StoreModule''. Are you sure it exists?";
59 print STDERR $/, __FILE__, ": Error while loading was: $@";
63 unshift (@Onis::Data::Persistent::ISA, $mod_name);
70 The child-modules have to provide the following interface:
74 =item B<Onis::Data::Persistent-E<gt>new> (I<$name>, I<$key_name>, I<@field_names>)
76 This is the constructor for the objects that will hold the data. Some modules
77 may need a name for each field, and this is where plugins have to give the name
78 of each field. This is particularly important for backends using relational
79 databeses. I<$name> is merely a name for that variable or, in the database
82 Since this is a constructor it returns an object. The object "knows" the folling methods:
84 =item B<$obj-E<gt>get> (I<$key>)
86 Returns the data associated with the given I<$key> pair or an empty list if no
87 data has been stored under this tupel before..
89 =item B<$obj-E<gt>put> (I<$key>, I<@fields>)
91 Stores the given values in the data structure. How this is done is described
92 below in L<another paragraph>. Doesn't return anything. The number of entries
93 in I<@fields> has to match the number of entries in I<@field_names> when
94 creating the object using B<new>.
96 =item B<$obj-E<gt>keys> ([I<$field>, ...])
98 Returns a list of all the keys defined for this object. If one field is given
99 the list will be sorted by that field's values, if more fields are given the
100 list is sorted with the first field taking precedence over the others. If no
101 field is supplied the order is undefined.
103 =item B<$obj-E<gt>del> (I<$key>)
105 Deletes I<$key> and all fields associated with it.
111 The B<put> and B<get> methods can be found in the
112 B<Onis::Data::Persistent::None> module. Other modules are encouraged to inherit
113 from that module, but don't need to. The data is stored as follows: The object
114 that's returned to the caller is actually a hash with this layout:
120 key0 => [ qw(field0 field1 field2 ...) ],
121 key1 => [ qw(field0 field1 field2 ...) ],
122 key2 => [ qw(field0 field1 field2 ...) ],
127 The actual data is not directly stored under I<%object> so database backends
128 can store metadata there (table name, credentials, whatever..).
130 =head1 FURTHER CONSIDERATIONS
132 Backend modules will probably read the entire data at startup and save
133 everything at the end. Another strategy might be reading (at least trying to)
134 an entry when it's first tried to B<get>..
138 Florian octo Forster, L<octo@verplant.org>. Any comments welcome as long as I
139 haven't started implementing this ;)