View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Dale Amon > DMAMisc-1.01-3 > DMA::ldconfig



Annotate this POD

View/Report Bugs


 DMA::ldconfig - Load configuration variables from database.


 use DMA::ldconfig
 $t = load_local_configuration ($db, $usr, $pass); 

Inheritance ^


Description ^

Most programs have a need for configuration and this lets you keep all of your configuration data in a MySQL database. To use it there must be a configuration Table defined this way:

 CREATE TABLE configuration (
              Name   VARCHAR(100)  NOT NULL, 
              Value  VARCHAR(100)  NOT NULL, 
 PRIMARY KEY  (Name));

If you are setting this up for the first time, you might do something like the following. First make sure the user of this database has a password set. You can set it:

 mysqladmin -u cfguser --password= password foobaz

or change it:

 mysqladmin -u cfguser --password=foobaz password newbar

Then create the database and load your definition file

  mysqladmin -u cfguser --password=newbar create mydatabase
  mysql -u cfguser --password=newbar < base.mysql

Where 'base.mysql' (or whatever) contains the lines needed to set up the database:

 use mydatabase;
 CREATE TABLE configuration (
              Name   VARCHAR(100)  NOT NULL, 
              Value  VARCHAR(100)  NOT NULL, 
 PRIMARY KEY  (Name));
 INSERT INTO configuration VALUES ("MYVAR",    "True");
 INSERT INTO configuration VALUES ("MYNUMVAR", "5");

Note that DMA::ldconfig imports its single function into your name space. You should run it in the MAIN namespace so all of your configuration variable are imported into that namespace for easy global usage. To avoid the possibility of namespace collision you should not use a prefix of '$::CFG_' on any of your variables.

After running load_local_configuration ("mydbname", "cfguser", "newbar") with the above example, your main namespace would contain the scalar variable Names $::CFG_MYVAR and $::CFG_MYNUMVAR initialized to the Values shown in the table example. By re-running this routine you can dynamically update your default values, a feature which is both useful and potentially perilous.

If it is not obvious, to use this class you must have a MySQL database server running and accepting localhost connections.

Since the class is based on the Perl DBI class, it would be very easy to change to a different database.

Note that MySQL requires a license for commercial use. The licenses are quite inexpensive.

Examples ^

 use DMA::ldconfig
 $t = load_local_configuration ("mydbname", "cfguser", "newbar");
 if ($::CFG_MYVAR eq "True") {print "Yep, we got it!");

Variables ^


Functions ^

$t = load_local_configuration ($db, $usr, $pass)

Load the contents of a configuration table taken from local MySQL database $db. Connect to it as user $usr with password $pass. For every Name and Value pair in the table's records, generate $::CFG_thisname = $thisvalue. Return true if it this succeeds.

Private Functions ^



 See TODO.




Dale Amon <>

syntax highlighting: