Greetings Monks,
I've recently been working on a small personal CMS that uses YAML instead of a Database for everything. One bit of what I felt was sublime coolness was when I was adding config directives for Template configuration (where to find various types of templates, include path, etc) and a snippet from that config file looked like this:
include_dir: /home/trizor/site/templates post_template: post.tt
And was used like this:
use Template; use YAML::Syck qw(LoadFile); my $config = LoadFile(glob("~/.siteconf")); my $tt = Template->new() # Other config parts are irrelevant $tt->process($config->{post_template},\%vars);
Now this is a very stripped down template for the sake of example, but you get the idea. Now Template vets can skip this sentence, but process() takes the template as the first argument and can use either the filename of a template, or the actual template as a scalar ref. This is where the Power Configuring occurs.
We all know YAML is a serialization format (If you don't, now you do), and since a scalar ref is just another perl data structure that can be serialized, so if I want to just specify the template in the config file and not have to keep track of a separate one, I can.
If I change the config file to read:
post_template: !!perl/ref =: | [% var1 %] # Formatting funness! [% var2 %]
Template gets its scalar ref and uses the template in the config file. Now that's what I call a power configuration format.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Power YAML Config
by friedo (Prior) on Apr 18, 2007 at 18:34 UTC |