[Catalyst] YAML Config

Daniel Hulme st at istic.org
Tue Jul 24 15:37:32 GMT 2007


On Tue, Jul 24, 2007 at 02:43:37PM +0100, Dave Howorth wrote:
> Oleg Pronin wrote:
> > Hi.
> >  
> > I would like to use references to variables that have been defined in my
> > yaml config.
> >  
> > Something like this:
> >  
> > var_dir: &var __path_to(var)__
> >  
> > log_dir: &log *var/log
> > log_file: *log/file.txt
> >  
> > This is a feature of YAML 1.0.
> 
> Can you give a specific reference to the place in the YAML spec that
> says this is allowed? I can only find statements about aliases to nodes
> (i.e. what you call pure aliases). I can't see any provision for
> substituting values and then adding to them. So the modules are simply
> implementing the YAML spec, on my reading.

I have to second what Dave says. YAML doesn't have "variables", it just
has nodes. An alias just gets you another copy of the referenced node,
no matter whether it's a string, an integer, a hash, a list, or
whatever. This string concatenation idea you want isn't part of YAML at
all. It doesn't seem like the sort of thing the YAML people would be
willing to add, since alias nodes do actually define references not just
copies.

If repeating the value of var_dir is too much for you, I can only
suggest you specify inside your application that the value of log_dir
&c. is appended to the value of var_dir unless it's an absolute path, so
you end up with something like:

---
var_dir: __path_to(var)__
log_dir: log
...

and then in your code

my $log_dir = $config{log_dir} =~ m!^/!
              ? $config{log_dir}
              : $config{var_dir}.'/'.$config{log_dir};

(Warning: above code may not actually work.)

-- 
Every program eventually reaches a point where it becomes harder to make
a simple change than to rewrite the program from scratch. Unfortunately,
when this point is reached, it is far too late to consider rewriting it.
http://surreal.istic.org/                              Show, don't tell.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070724/99ded067/attachment.pgp


More information about the Catalyst mailing list