[CDBI] Turning Class::DBI on its side

Duncan Ferguson duncan_j_ferguson at yahoo.co.uk
Wed Jul 25 14:32:42 BST 2007


Bit of a strange cry for help this (not written a module before so  
some of my terminology is probably off, sorry)

I want to turn the Class::DBI objects on their side; I want to store  
some application configuration within a database table, i.e.

Table: prefs
+----+------------------+----------------------------+
| id | name             | value                      |
+----+------------------+----------------------------+
|  0 | filename         | /path/to/file.txt          |
|  1 | item_enabled     | 1                          |
|  2 | task_name        | something                  |
+----+------------------+----------------------------+

so instead of doing

my $row=DB::Prefs->search({ name => " filename}})->first;
print $row->value,$/;
$row->value("/new/path/to/file");

I can do

print DB::Prefs->filename,$/;

or

DB::Prefs->filename("/new/path/to/file");

So, how I can set up the accessors to point to a row in the database  
rather than a column?  There should only be one row per name (so name  
could be a primary key rather than id).  I can see that I probably  
have to provide/create each accessor for each distinct item in the  
table (or do a generic AUTOLOAD one to search for the item and get  
the value) but how do I create the correct object to be returned to  
the caller?

TIA

   Duncs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/pipermail/classdbi/attachments/20070725/a5c6a03b/attachment.htm


More information about the ClassDBI mailing list