[Dancer-users] Changing config hashref directly (was: Re: Dancer::layout has been deprecated)

David Precious davidp at preshweb.co.uk
Sun May 22 13:46:13 CEST 2011


On Saturday 21 May 2011 23:19:18 Naveed Massjouni wrote:
> Is config->{layout} = 'foo' the same as set layout => 'foo'?

In general, you shouldn't change the hashref returned by config(), but use 
set() instead.  Some settings, when changed via set(), trigger a hook to 
handle that change (e.g. initialise a template engine when 'template' is used, 
set up a catch-all route when 'auto_page' is used, etc).  Changing them 
directly, bypassing set(), means those triggers won't fire.

The 'layout' setting, however, doesn't have any trigger, so changing it 
directly wouldn't hurt; I still wouldn't recommend it though, for future-
proofing.

In fact, it might make sense for us to change config() to return a tied hash 
which emits warnings if you try to change any values, to discourage people 
from using it to change settings directly, bypassing set().

Cheers


-- 
David Precious  ("bigpresh")
http://www.preshweb.co.uk/

   "Programming is like sex. One mistake and you have to support
   it for the rest of your life". (Michael Sinz)


More information about the Dancer-users mailing list