The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Puppet::Storage - Utility class to handle permanent data

SYNOPSIS

 use Puppet::Storage ;

 my $file = 'test.db';
 my %db;

 # you manage the DB file
 tie %db, 'MLDBM', $file , O_CREAT|O_RDWR, 0640 or die $! ;

 # translucent attributes
 Puppet::Storage->dbHash(\%db);
 Puppet::Storage->keyRoot('key root');

 my $foo = new Puppet::Storage (name => 'foo');
 my $bar = new Puppet::Storage (name => 'bar');

 # store some data in permanent storage
 $foo->storeDbInfo(toto => 'toto val', dummy => 'null') ;

 # remove some data from permanent storage
 $bar->deleteDbInfo('dummy');

 # at the end of your program, just to be on the safe side
 untie %dbhash ;

DESCRIPTION

Puppet::Storage is a utility class which provides a facility to store data on a database file tied to a hash.(with MLDBM)

Class data

These items are translucent attributes (See perltootc by Tom Christiansen).

Using the following method, you may set or query the value for the data class. And these parameters may be overridden with the constructor or by invoking this method by the object rather than by the class.

keyRoot

See "Database management".

dbHash

ref of the tied hash. See "Database management".

Constructor

new(...)

Creates new Puppet::Storage object. New() parameters are:

name

The name of your object (no defaults)

spawn(...)

Spawn a new Puppet::Storage object re-using the translucent attribute of the spawner object.

parameters are:

name

The name of your object (no defaults)

child(...)

Spawn a new Puppet::Storage object re-using the translucent attribute of the spawner object. On top of that a new keyRoot attribute is defined as '<parent_keyroot child_name';

E.g. if the parent keyroot is 'foo', the parent name is 'bar', the child name is 'calvin', then the new keyRoot of the child is set to 'foo bar'. So for instance a 'toto' data will be stored in the child with this key: 'foo bar;calvin#toto'. That's pretty complex, fortunately, you shouldn't have to worry about the key managment.

parameters are:

name

The name of your object (no defaults)

Database management

The class is designed to store its data in a database file. (For this you should use MLDBM if you want to store more than a scalar in the database). The key for this entry is "$keyRoot;$name# $key". keyRoot and name being passed to the constructor of the object and 'key' is the name of the value you want to store (This may remind perl old timers of a trick to emulate multi-dimensional hashes in perl4)

Needless to say, creating two instances of Puppet::Storage with the same dbHash, keyRoot and name is a bad idea because you may mix up data from one object to another.

storeDbInfo(%hash)

Store the passed hash in the database. You may also pass a hash ref as single argument.

deleteDbInfo(key,...)

delete the "key" entries from the database.

getDbInfo(key,...)

If one key is specified, getDbInfo will return the value of the "key" entry from the database.

If more than one key is passed, getDbInfo will return a hash ref containing a copy of the key,value pairs from the database.

dumpDbInfo()

dumpDbInfo will return a hash ref containing a copy of all the permanent data of this object.

Using this method should only be used for debug purpose as it will iterate over all the other values of the DB_File to get the data of this object.

AUTHOR

Dominique Dumont, Dominique_Dumont@grenoble.hp.com

Copyright (c) 1999 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl, Puppet::Body