Nicer Configuration Files
Randal L. Schwartz
I see a lot of configuration file modules in the CPAN. Perhaps too many. Perhaps
this is a task that (like so many others) attracts every new junior Perl programmer
into the "I can do better than those" mindset.
I can't claim to have used every one, and perhaps I haven't even looked at
every one. However, let me spend a bit of time talking about one that I used
rather heavily on a recent project and that I am definitely liking for future
projects.
One of my favorite clients is http://geekcruises.com, mostly because
the typical work location for GeekCruises is aboard a cruise ship traveling
between the Caribbean islands. I recently completed a major overhaul of the
company's administrative interface to the "booking engine": the portion of the
Web site that makes money for them by allowing random geeks to sign up for future
cruises.
The core of my overhaul used the emerging standard CGI::Prototype framework,
along with Template Toolkit and Class::DBI for the data model. One of
the problems I face when programming is how to write each important fact in
only one location, because cut-and-paste is a maintenance nightmare. I found
myself wanting to record meta-information about each of the database fields
(there are some 500 columns in 50 tables for this application) in a common location.
I wanted to access the information from both Perl code and Template Toolkit
code, because a lot of the meta-information bridges the "model" (the precise
column of that table) to the "view" (how the user sees the data and how the
inputs are interpreted). I decided rather early on that I wanted to call a method
named Config against a given Class::DBI table class, or a specific
row instance, and that this should return a hashref of all the meta-information
about this row.
|