abw/Template2 — pull request #12 by colinmkeith (2012-07-08 03:16:41+00:00)
Title: Changed _template_content() to fail on PROCESSing directory to prevent cache corruption

lib/Template/Provider.pm: _template_content() now fails on opening directories.

open() does not fail, but acts like directory is an empty file, so when caching is enabled the PROCESS'ed template is created, without error, as a 0b files in the cache folder. This means that templates within that folder can't have cache files created because the template directory structure is used in the cache.

E.g. If I have template/profiles/user.tmpl and accidentally PROCESS 'profiles' then a 0b file is created in the cache under the name "profiles". Accordingly when I PROCESS 'profiles/user.tmpl' then the cache can't write to cachedir/profiles/user.tmpl because cachedir/profiles is a file not a directory.

PROCESS'ing a directory doesn't make sense so it should fail as an error.

Also changed _load() to use $error returned from _template_content(). This allows the caller to understand the error instead of getting back "$alias: $!". In the case of PROCESS'ing a directory we explicitly test with -d so there is no error set in $!, and it defaults to the meaningless "No such file or directory" instead of the error message that we defined ('not a file')