Subject: | Gracefully handling empty config files |
Hey Mark,
I've been exercising your module lately and have a request. I use a perl format for my config files. If I mess up the syntax, the following error will appear the next time I try to run my application:
Can't use an undefined value as a HASH reference at /loader/0x82501f0/CGI/Application/Plugin/ConfigAuto.pm line 121, line 887.
Line 121 combines previously loaded config files with new ones:
%combined_cfg = (%combined_cfg, %$cfg);
I have no idea what the reference to line 887 is (my config file is only 450 lines).
I can run perl -cw <config-file> to find out where I've made the mistake and get back to work. However, the first time that error came up, it wasn't very clear the problem. A simple test such as the following would make my life easier (esp. the next time this happens and I've forgotten about this problem):
die "No configuration found. Check your config file (check the syntax if this is a perl format)." unless keys %combined_cfg;
I'm kinda surprised that Config::Auto isn't throwing an error when it tries to eval the invalid code. Perhaps there's an eval{} somewhere that I'm overlooking.
William