The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Puppet::Storage - Utility class to handle permanent data

SYNOPSIS

 use Puppet::Storage ;

 package myClass ;
 sub new
  {
    my $type = shift ;
    my $self = {};
    $self->{storage} = new Puppet::Storage(@_) ;
    bless $self,$type ;
  }

 package main ;

 # create a class with persistent data
 my $file = 'test.db';
 my %dbhash;
 # you manage the DB file
 tie %dbhash, 'MLDBM', $file , O_CREAT|O_RDWR, 0640 or die $! ;

 my $test = new myClass 
   (
    name => 'test',
    dbHash => \%dbhash,
    keyRoot => 'key root'
   );

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

 # remove some data from permanent storage
 $test->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)

Constructor

new(...)

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

name

The name of your object (no defaults)

keyRoot

See "Database management".

dbHash

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

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